今天在写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的更多相关文章

  1. 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 ...

  2. Arcmap 安装完后使用出现visual fortran run-time error的解决方法

    今天将ArcGIS安装到自己的XP笔记本上,安装过程一帆风顺,但打开Arcmap使用的时候,出现了visual fortran run-time error. 下面是解决方法: 下载个Dforrt.d ...

  3. Qt Sqlite qwt 发布过程中碰到的问题runtime error

    qt版本:4.8.0 qwt版本:6.1.2 使用dll show检测缺少的dll,或者笨一点的方法,点击运行差什么找什么放进去: 左上显示exe调用哪些dll,右边是dll又再次调用啦哪些dll: ...

  4. Codeforce - Runtime Error

    Bahosain was trying to solve this simple problem, but he got a Runtime Error on one of the test case ...

  5. IE Unknown runtime error

    1. 在函数中使用原生的js的时候,有时在IE下会出现Unknown runtime error 火狐下正常 2. 解决办法, 将原生js改成jquery处理兼容问题 document.getElem ...

  6. Microsoft Visual C++ Runtime error解决方法

    1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...

  7. Microsoft Visual C++ Runtime Library Runtime Error的解决的方法

    打开浏览器时,出现Microsoft Visual C++ Runtime Library Runtime Error错误,初步预计是软件冲突,可能有多种出错的方式,我的是浏览器自己主动关闭. 一. ...

  8. UVa 1402 Runtime Error 伸展树

    Runtime Error 到现在连样例也跑不出来!!! 调试了一晚上快要死了…… 知道错在哪里但是不会改,代码先扔在这里吧.看来不能太依赖模板啊orz…… #include <cstdio&g ...

  9. Mindjet MindManager 2012 从模板创建出现“Runtime Error pure virtual function call” 解决方法

    我的Mindjet MindManager 2012 Pro也就是MindManager10 在应用模板之后总会显示 Microsoft Visual C++ Runtime Library Runt ...

随机推荐

  1. [PHP] Laravel 5.5 打印SQL语句

    [PHP] Laravel 5.5 打印SQL语句 四种方法 第一种方法: 打印SQL默认是关闭的,需要在/vendor/illuminate/database/Connection.php中打开. ...

  2. 某神奇的cf跳转插件

    // ==UserScript== // @name Codeforces快速跳转菜单 // @namespace http://tampermonkey.net/ // @version 2019. ...

  3. P3386 【模板】二分图匹配(匈牙利算法)

    题目背景 二分图 题目描述 给定一个二分图,结点个数分别为n,m,边数为e,求二分图最大匹配数 输入输出格式 输入格式: 第一行,n,m,e 第二至e+1行,每行两个正整数u,v,表示u,v有一条连边 ...

  4. Codeforces 161.D. Distance in Tree-树分治(点分治,不容斥版)-树上距离为K的点对数量-蜜汁TLE (VK Cup 2012 Round 1)

    D. Distance in Tree time limit per test 3 seconds memory limit per test 512 megabytes input standard ...

  5. Kubeasz部署K8s基础测试环境简介

    下面介绍使用Kubeasz部署K8s集群环境. https://github.com/easzlab/kubeasz在需要使用kubeeasz项目安装的k8s时,需要将所有需要它来部署的节点上,都安装 ...

  6. 【AtCoder】 ARC 100

    link C-Linear Approximation 给出\(N\)个数\(A_1,A_2,...,A_N\) ,求一个数\(d\),最小化\(\sum_{i=1}^N|A_i-(d+i)|\) 把 ...

  7. RocketMQ常用命令【转】

    首先进入 RocketMQ 工程,进入/RocketMQ/bin   在该目录下有个 mqadmin 脚本 . 查看帮助:   在 mqadmin 下可以查看有哪些命令 a: 查看具体命令的使用 :  ...

  8. S905系列的uboot分析

    Ubuntu18.04通过PL2303HX连接TTL 接线的连接 PL2303的3.3V悬空, TX接盒子RX, RX接盒子TX, GND接盒子GND 终端选择 系统自带pl2303的驱动, 可以通过 ...

  9. UICachedDeviceRGBColor CGImage]: unrecognized selector sent to instance 0xxxxxxxxxxx'

    UICachedDeviceRGBColor CGImage]: unrecognized selector sent to instance 0xxxxxxxxxxx' 报错原因是 本来应该写空间的 ...

  10. Error-ASP.NET:此 SqlTransaction 已完成;它再也无法使用。

    ylbtech-Error-ASP.NET:此 SqlTransaction 已完成:它再也无法使用.  1.返回顶部 1. “/”应用程序中的服务器错误. 此 SqlTransaction 已完成: ...