LeetCode OJ Linked List Cycle II
来源:互联网 发布:淘宝网店在哪里看 编辑:程序博客网 时间:2024/06/16 06:31
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?
So ingenious, from http://www.cnblogs.com/jack204/archive/2011/09/14/2175559.html
class Solution {public: ListNode *detectCycle(ListNode *head) { ListNode *temp_1 = head; ListNode *temp_2 = head; ListNode *meetPoint; bool loop = false; while (temp_2 != NULL && temp_2->next != NULL) { temp_1 = temp_1->next; temp_2 = temp_2->next->next; if (temp_1 == temp_2) { meetPoint = temp_1; loop = true; break; } } if (!loop) { return NULL; } else { temp_1 = head; temp_2 = meetPoint; while (temp_1 != temp_2) { temp_1 = temp_1->next; temp_2 = temp_2->next; } return temp_1; } }};
0 0
- LeetCode OJ:Linked List Cycle II
- LeetCode OJ Linked List Cycle II
- [LeetCode OJ] Linked List Cycle II 解题报告
- <LeetCode OJ> 141 / 142 Linked List Cycle(I / II)
- LeetCode OJ:Linked List Cycle
- [LeetCode OJ]Linked List Cycle
- LeetCode OJ Linked List Cycle
- 【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
- C++中数字与字符串之间的转换
- LeetCode OJ Partition List
- java.io中的字符流简单介绍
- ZOJ1003(1)
- LeetCode OJ Reverse Linked List II
- LeetCode OJ Linked List Cycle II
- 每个Java程序员必须知道的5个JVM命令行标志
- LeetCode OJ Linked List Cycle
- leetcode 之Rotate Array
- LeetCode OJ Insertion Sort List
- LeetCode OJ Sort List
- LeetCode OJ Max Points on a Line
- hdu 4463 Outlets(最小生成树)
- linux 下实线文件切割--split