LeetCode之旅(33)
来源:互联网 发布:apl美皇公司知乎 编辑:程序博客网 时间:2024/06/06 03:52
Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull
.
Follow up:
Can you solve it without using extra space?
参考了一篇博客:http://www.cnblogs.com/x1957/p/3406448.html
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *detectCycle(ListNode *head) { if (!head) return NULL; ListNode *slow = head, *fast = head; while (fast) { if (fast) fast = fast->next; if (fast) fast = fast->next; if (slow) slow = slow->next; if (fast && fast==slow) { slow = head; while (slow != fast) fast = fast->next, slow = slow->next; return slow; } } return NULL; }};
0 0
- LeetCode之旅(33)
- LeetCode之旅(2)
- LeetCode之旅(3)
- LeetCode之旅(4)
- LeetCode之旅(5)
- LeetCode之旅(6)
- LeetCode之旅(7)
- LeetCode之旅(8)
- LeetCode之旅(9)
- LeetCode之旅(10)
- LeetCode之旅(12)
- LeetCode之旅(13)
- LeetCode之旅(14)
- LeetCode之旅(15)
- LeetCode之旅(16)
- LeetCode之旅(17)
- LeetCode之旅(18)
- LeetCode之旅(19)
- Myeclipse 8.6续约注册码
- 栈实现二进制转十进制
- 关于数据测试
- hdu1255 扫描线,矩形重叠面积(两次以上)
- 设计模式——三大工厂
- LeetCode之旅(33)
- 乌拉姆数列 Euler167
- 深搜dfs
- hibernate初学者可能碰到的一些问题
- iOS 博客资源精选
- OpenCV 实践程序12——用分类器对视频进行人脸检测
- Go_Json_Unmarshal_Marshal
- 付金额接姑婆过去
- 枚举和联合体