[Leetcode]Linked List Cycle II
来源:互联网 发布:sql实例名称无效 编辑:程序博客网 时间:2024/06/07 09:47
Given a linked list, return the node where the cycle begins. If there is no cycle, return null
.
Follow up:
Can you solve it without using extra space?
class Solution {public: ListNode *detectCycle(ListNode *head) { if(head ==NULL) return NULL; ListNode* fast = head; ListNode* slow = head; while(fast->next && fast && fast->next->next) { fast = fast->next->next; slow = slow->next; if(fast == slow) { slow = head; while(fast != slow) { fast = fast->next; slow = slow->next; } return fast; } } return NULL; }};
0 0
- 【LeetCode】 Linked List Cycle II
- Leetcode: Linked List Cycle II
- <Leetcode>Linked List Cycle II
- [LeetCode] Linked List Cycle II
- Leetcode: Linked List Cycle II
- LeetCode:Linked List Cycle II
- Leetcode Linked List Cycle II
- [LeetCode]Linked List Cycle II
- leetcode Linked List Cycle II
- LeetCode | Linked List Cycle II
- Leetcode: Linked List Cycle II
- [LeetCode] - Linked List Cycle II
- Leetcode: Linked List Cycle II
- LeetCode - Linked List Cycle II
- leetcode Linked List Cycle II
- Linked List Cycle II -- LeetCode
- LeetCode Linked List Cycle II
- [LeetCode] Linked List Cycle II
- 【转载】fscanf和fprintf函数从文件中格式化读取double型数据
- 详解Oracle DELETE和TRUNCATE 的区别
- 问题相关
- 四个开源商业智能平台比较(五)
- 可以捕获报错的sql语句的触发器
- [Leetcode]Linked List Cycle II
- webview loadUrl() 弹出系统浏览器解决办法
- swift语言设计模式介绍-创建型模式
- selenium验证页面元素
- C++ 中可确定的内置类型的大小关系
- [Leetcode]Merge Two Sorted Lists
- Mac如何正确的卸载程序
- 快速排序(分治法实现的随机化版本)
- Android 的MVC