LeetCode runtime error
今天在写LeetCode的某一道题目时候,遇到runtime error问题,本地能过,submit后死活不能通过。
查了一下网上的一些答案,基本上都是数组、指针没有初始化造成野指针、数组索引值越界。
看了自己的代码觉得没啥问题,没有到数组,那只能够是链表的指针变成野指针的问题。仔细看了两遍代码,终于发现是链表里的random指针没有初始化,在调用的时候很容易野。
Problem:
给定一个链表,每个节点包含一个额外增加的随机指针,该指针可以指向链表中的任何节点或空节点。
要求返回这个链表的深度拷贝。
有问题的代码片段:
while(currentNode != NULL)
{
temp = (struct RandomListNode*)malloc(sizeof(struct RandomListNode));
temp->label = currentNode->label;
temp->next = currentNode->next;
currentNode->next = temp; currentNode = temp->next;
}
加了初始化指针的代码:
while(currentNode != NULL)
{
temp = (struct RandomListNode*)malloc(sizeof(struct RandomListNode));
temp->label = currentNode->label;
temp->next = currentNode->next;
temp->random = NULL; //就是这里出的问题,如果没有初始化成NULL的话,指向的为止不知道是哪里,服务器会访问出错
currentNode->next = temp; currentNode = temp->next;
}
LeetCode runtime error的更多相关文章
- com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address: bind
在发布 web service 时报错: Endpoint.publish(publishAddress, hl7MessageReveiver); com.sun.xml.internal.ws.s ...
- Arcmap 安装完后使用出现visual fortran run-time error的解决方法
今天将ArcGIS安装到自己的XP笔记本上,安装过程一帆风顺,但打开Arcmap使用的时候,出现了visual fortran run-time error. 下面是解决方法: 下载个Dforrt.d ...
- Qt Sqlite qwt 发布过程中碰到的问题runtime error
qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...
- Codeforce - Runtime Error
Bahosain was trying to solve this simple problem, but he got a Runtime Error on one of the test case ...
- IE Unknown runtime error
1. 在函数中使用原生的js的时候,有时在IE下会出现Unknown runtime error 火狐下正常 2. 解决办法, 将原生js改成jquery处理兼容问题 document.getElem ...
- Microsoft Visual C++ Runtime error解决方法
1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...
- Microsoft Visual C++ Runtime Library Runtime Error的解决的方法
打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. ...
- UVa 1402 Runtime Error 伸展树
Runtime Error 到现在连样例也跑不出来!!! 调试了一晚上快要死了…… 知道错在哪里但是不会改,代码先扔在这里吧.看来不能太依赖模板啊orz…… #include <cstdio&g ...
- Mindjet MindManager 2012 从模板创建出现“Runtime Error pure virtual function call” 解决方法
我的Mindjet MindManager 2012 Pro也就是MindManager10 在应用模板之后总会显示 Microsoft Visual C++ Runtime Library Runt ...
随机推荐
- pytest . class
#在当前测试类的开始与结束执行. setup_class teardown_class #在每个测试方法开始与结束执行. setup teardown #在每个测试方法开始与结束执行,与setup/t ...
- Features Track[STL map]
目录 题目地址 题干 代码和解释 参考 题目地址 Features Track(ACM-ICPC 2018 徐州赛区网络预赛 ) 题干 代码和解释 题意:一个动画有许多 n 帧,每帧有 k 个点,点的 ...
- 从技术角度看Pacs厂商
天健PACS较早从事影像医院处理系统,为国外系统或设备以OEM方式提供软件模块.天健的PACS里面三维重建.容积重建.血管分析.虚拟腔镜.头部灌注等部分是用西安盈谷科技的,手术麻醉和重症监护系统是奥迪 ...
- /etc/resolv.conf文件中的search项作用
resolv.conf文件中有search项时,主机名解析规则顺序: DNS配置文件如下: # vi /etc/resolv.conf # Generated by NetworkManager se ...
- 响应: 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
原vsftpd服务器的系统从centos6.8升级到centos7.2.vsftpd使用yum方式安装,用户采用系统用户登录.由于系统升级到centos7,yum安装的vsftpd版本改变.因此按ce ...
- ubuntu16.04 overlay 不支持redirect_dir开关
modinfo overlay--查看overlay版本 通过linux网站--https://elixir.bootlin.com/linux/v4.4.196/source/fs/overlayf ...
- S905系列的uboot分析
Ubuntu18.04通过PL2303HX连接TTL 接线的连接 PL2303的3.3V悬空, TX接盒子RX, RX接盒子TX, GND接盒子GND 终端选择 系统自带pl2303的驱动, 可以通过 ...
- (转)2019年 React 新手学习指南 – 从 React 学习线路图说开去
原文:https://www.html.cn/archives/10111 注:本文根据 React 开发者学习线路图(2018) 结构编写了很多新手如何学习 React 的建议.2019 年有标题党 ...
- cmd 域名生效检测
nslookup -qt=ns xxx.baidu.comnslookup -qt=txt xxx.baidu.com
- 怎样在sql server profiler跟踪时只显示自己关心的内容
当我们想知道.net程序到底执行了哪些SQL的时候,通常会使用sql server profiler,但是如果不加设置,我们程序执行的sql通常会被系统的SQL淹没,通过以下的方法,可以只显示我们需要 ...