2.5-找链表环的起点(same in LeetCode)
来源:互联网 发布:矩阵奇异值分解过程 编辑:程序博客网 时间:2024/06/11 01:53
Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.
DEFINITION
Circular linked list: A (corrupt) linked list in which a node’s next pointer points to an earlier node, so as to make a loop in the linked list.
EXAMPLE
Input: A -> B -> C -> D -> E -> C [the same C as earlier]
Output: C
leetcode:Linked List Cycle II
http://blog.csdn.net/todorovchen/article/details/24052849
ListNode *detectCycle(ListNode *head){ if(head==NULL) return NULL; ListNode *slow = head, *fast = head; while(fast != NULL && fast->next != NULL) { slow = slow->next; fast = fast->next->next; if(slow == fast)// first meet { slow=head; while(slow != fast) { slow = slow->next; fast = fast->next; } return slow;// second meet } } return NULL;}
0 0
- 2.5-找链表环的起点(same in LeetCode)
- 8.5-有效的括号组合(same in LeetCode)
- 1.6-Rotate Image(same in LeetCode)
- 2.2-找链表倒数第k个(same in LeetCode)
- 2.4-链表模拟整数加法(same in LeetCode)
- 4.1-判断二叉树是否平衡(same in LeetCode)
- 4.4-按行输出二叉树(same in LeetCode)
- [LeetCode] Text Justification (put words in lines with same length)
- [Leetcode] Same Tree奇妙的现象
- LeetCode 142: Linked List Cycle II 输出链表中环的起点
- [LeetCode] Unique Paths 起点与终点确定的路径数
- LeetCode: Same Tree
- LeetCode Same Tree
- [Leetcode] Same Tree
- LeetCode : Same Tree
- [LeetCode] Same Tree
- leetcode 65: Same Tree
- Leetcode 100 Same Tree
- PHP之单例模式
- navigation drawer
- C/C++--C++获取目录下的文件列表
- Incorrect column count: expected 1, actual 10 IncorrectResultSetColumnCount
- java泛型
- 2.5-找链表环的起点(same in LeetCode)
- scala学习八 模式匹配之领域语言
- 贝叶斯分类器
- [经验分享]长期有效的推广网店的方法
- Manacher算法:求解最长回文字符串,时间复杂度为O(N)
- MPI & OpenMP
- 文本文件与二进制文件区别
- java使用正则表达式
- Dijkstra?+spfa+路径的记录