LeetCode每日一题 142. 环形链表 II
生活随笔
收集整理的這篇文章主要介紹了
LeetCode每日一题 142. 环形链表 II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接
思路
快慢指針
class Solution { public:ListNode *detectCycle(ListNode *head) {ListNode* l = head;ListNode* r = head;while (r && r->next) {l = l->next;r = r->next->next;if (l == r) break;}if (!r || !(r->next)) return nullptr;r = head;while (l != r) {l = l->next;r = r->next;}return l;} };總結
以上是生活随笔為你收集整理的LeetCode每日一题 142. 环形链表 II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode每日一题 141. 环形
- 下一篇: LeetCode每日一题 416. 分割