Linked List Cycle
来源:互联网 发布:啤酒杯 知乎 编辑:程序博客网 时间:2024/05/01 08:54
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
/** * 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) { ListNode *fastPoint = head; ListNode *slowPoint = head; if(fastPoint == NULL || fastPoint->next == NULL) return false; while(fastPoint->next != NULL && fastPoint->next->next != NULL) { fastPoint = fastPoint->next->next; slowPoint = slowPoint->next; if(fastPoint == slowPoint) return true; } return false; }};
0 0
- leetcode Linked List Cycle & Linked List Cycle ||
- Linked List Cycle II Linked List Cycle
- 【LeetCode】Linked List Cycle
- Leetcode: Linked List Cycle
- Leetcode Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Leetcode: Linked List Cycle
- LeetCode:Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Linked List Cycle II
- [LeetCode]Linked List Cycle
- Linked List Cycle
- LeetCode | Linked List Cycle
- &&的短路原理
- ExtJS MVC架构讲解
- Notepad++中的复活节彩蛋(easter egg)
- Ubuntu文件标示解释
- 黑马程序员_Java基础知识总结
- Linked List Cycle
- 2013年传智播客视频教程.net/ios/php/java/安卓/C++/平面设计/c全套教程分享1
- Image uImage与zImage的区别【转】
- iOS处理图片
- 静心,很舒服的几句话
- 使用loadrunner遇见的问题
- 入侵必备DOS命令总结
- 语音群呼促进企业营销大力推广
- 实验二 算法基本功 与 综合思考