[Leetcode]Linked List Cycle II
来源:互联网 发布:淘宝卖家怎么做直播 编辑:程序博客网 时间:2024/06/03 19:42
//list链表的题目
class Solution {
public:ListNode *detectCycle(ListNode *head) {
if(head==NULL)
return NULL;
ListNode *first=head;
ListNode *second=head;
ListNode *temp;
while(second->next!=NULL && second->next->next!=NULL)
{
first=first->next;
second=second->next->next;
if(first==second)
{
first=head;
while(first!=second)
{
second=second->next;//这里很重要,是link list的重点理解之处
first=first->next;
}
return first;
}
}
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
- 数据结构之AVLTree(04-1:Root of AVL Tree)
- Decode Ways - Leetcode
- poj 1125 最短路
- 基于经济学视角对我国职业教育起源进行探讨
- C#——调用exe程序并运行
- [Leetcode]Linked List Cycle II
- Binary Tree Level Order Traversal II
- iptables
- c#函数覆盖、隐藏、重载个人总结
- [Leetcode]Linked List Cycle
- 数据结构之排序
- 【BZOJ 1086】 [SCOI2005]王室联邦
- Linux 如何调整虚拟内存大小
- uva213信息解码