LeetCode 142. Linked List Cycle II
来源:互联网 发布:冒泡排序的算法思想 编辑:程序博客网 时间:2024/05/03 06:55
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull
.
Note: Do not modify the linked list.
Thousands of articles to introduce this idea. This is really very neat.
ListNode *detectCycle(ListNode *head) { if(!head) return NULL; ListNode* slow = head; ListNode* fast = head; while(fast && fast->next && fast->next->next) { slow = slow->next; fast = fast->next->next; if(slow == fast) { break; } } if(!fast || !fast->next || !fast->next->next) return NULL; // remember to check the no circle condition. slow = head; while(slow != fast) { slow = slow->next; fast = fast->next; } return slow; }
0 0
- [LeetCode]141. Linked List Cycle【&142. Linked List Cycle II】
- leetcode--141. Linked List Cycle&&142. Linked List Cycle II
- LeetCode 141. Linked List Cycle && 142. Linked List Cycle II
- 142. Linked List Cycle II leetcode list
- LeetCode 142. Linked List Cycle II
- [LeetCode]142.Linked List Cycle II
- [leetcode] 142.Linked List Cycle II
- [leetcode] 142. Linked List Cycle II
- leetcode 142. Linked List Cycle II
- [Leetcode]142. Linked List Cycle II @python
- [LeetCode]142. Linked List Cycle II
- 142. Linked List Cycle II LeetCode
- LeetCode:142. Linked List Cycle II
- LeetCode--142. Linked List Cycle II
- LeetCode 142. Linked List Cycle II
- LeetCode 142. Linked List Cycle II
- LeetCode *** 142. Linked List Cycle II
- LeetCode 142. Linked List Cycle II
- 有些工具程序员不用也要掌握(想到就写,不定期更新)
- zsh 自定义命令提示符(PS1/ prompt)
- 在visual studio环境下简单在.cpp中调用python matplotlib
- Android 系统本地推送,只有推送,没有注册系统闹钟推送
- 【软工面试】一个文件有N个单词,每行一个,快速找出一个单词x,已知该单词出现的次数大于N/2
- LeetCode 142. Linked List Cycle II
- LeetCode 114. Flatten Binary Tree to Linked List
- FreeBSD IPF gateway 网关 连接 Windows 服务器自带 1723 PPTP VPN 拨号 619 错误的解决
- Linux e1000网卡驱动流程
- 开通自己的技术博客了,欢迎大家前来指正
- android二维码生成器 艺术二维码
- 失眠偶记
- 我的自拍123
- 那个我