/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
bool hasCycle(ListNode *head) {
if(!head->next||!head)
return false;
ListNode *pre=NULL,* cur=head; while(cur)
{
ListNode* tmp=cur->next;
cur->next=pre;
pre=cur;
cur=tmp;
}
return (pre==head);
}
};

这是出错代码,后来查找原因发现是第12行的空指针判断顺序有问题,应该为if(!head||!head->next)

141. 环形链表 LeetCode报错:runtime error: member access within null pointer of type 'struct ListNode'的更多相关文章

  1. leetcode 编译问题:Line x: member access within null pointer of type 'struct TreeNode'

    参考: LEETCODE 中的member access within null pointer of type 'struct ListNode' 解决 leetcode 编译问题:Line x: ...

  2. 力扣 报错 runtime error: load of null pointer of type 'const int'

    runtime error: load of null pointer of type 'const int' 要求返回的是int* 解决方案 1.指针使用malloc分配空间 用 int * p = ...

  3. uiautomatorviewer 查看元素报错: Error taking device screenshot: null 原因

    使用uiautomatorviewer 查看android某些页面元素,出现错误Error obtaining UI hierarchy  Reason: Error taking device sc ...

  4. Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer

    Heka 编译安装后 运行报错 panic: runtime error: cgo argument has Go pointer to Go pointer 解决办法: 1.  Start heka ...

  5. LeetCode 141. 环形链表(Linked List Cycle) 19

    141. 环形链表 141. Linked List Cycle 题目描述 给定一个链表,判断链表中是否有环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 ...

  6. 【LeetCode】141.环形链表

    题目描述 141.环形链表 给定一个链表,判断链表中是否有环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 -1,则在该链表中 ...

  7. Java实现 LeetCode 141 环形链表

    141. 环形链表 给定一个链表,判断链表中是否有环. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). 如果 pos 是 -1,则在该链表中没有环. ...

  8. Appium1.6启动ios9.3报错Original error: Sdk '9.3.5' was not in list of simctl sdks

    问题: 使用Apppium1.6启动ios9.3报错Original error: Sdk '9.3.5' was not in list of simctl sdks   我的启动配置如下 {   ...

  9. JS function document.onclick(){}报错Syntax error on token "function", delete this token

    JS function document.onclick(){}报错Syntax error on token "function", delete this token func ...

随机推荐

  1. 玩得一手好注入之order by排序篇

    看了之前Gr36_前辈在先知上的议题,其中有提到排序注入,这个在最近经常遇到这样的问题,所以先总结下order by 排序注入的知识. 0×00 背景 看了之前Gr36_前辈在先知上的议题,其中有提到 ...

  2. 20150103 海南铁汉vs哈尔滨毅腾

    本文首发于『懂球帝』 这一场球赛虽然极其普通,在各位懂球帝面前或许不值得一提,但它极具历史意义,因为这是海南第一个职业联赛队伍的首场正式比赛,同时也是海南铁汉队第一次在正式比赛中与球迷们见面. 稍做一 ...

  3. python图片黑白化

    #!/usr/bin/env python #-*- coding:utf-8 -*- from PIL import Image im = Image.open(r"C:\Users\wa ...

  4. POJ Widget Factory 【求解模线性方程】

    传送门:http://poj.org/problem?id=2947 Widget Factory Time Limit: 7000MS   Memory Limit: 65536K Total Su ...

  5. POJ 3616 Milking Time(加掩饰的LIS)

    传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  6. 学习scala trait

      // 类接口,但是可以实现方法 // 作用 多重继承 trait traitA{ val tnum: Int def log(msg: String): Unit ={ println(" ...

  7. centos修改hostname

    1.临时修改 hostname localhost 2.永久修改 vim /etc/sysconfig/network 修改hostname的值后保存

  8. jquery 跨域获取网页数据

    <script language="javascript" src="http://cbsahhs.blog.163.com/jquery.min.js" ...

  9. LeetCode5.最长回文子串 JavaScript

    给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1: 输入: "babad" 输出: "bab" 注意: &qu ...

  10. iOS之点击通知栏跳转应用的相关页面

    当远程推送通知到达应用,有3个相关的方法是用来处理这个通知的. - (BOOL)application:(UIApplication *)application didFinishLaunchingW ...