环形链表(成环的相交的节点在哪)(中等)(证明题)
142. 环形链表 II - 力扣(LeetCode)
题目
解题思路(证明一下)
这里的关键点在于你需要证明L==T
然后就可以解题
代码
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ typedef struct ListNode ListNode; ListNode *detectCycle(ListNode *head) { ListNode* fast = head; ListNode* slow = head; while(fast && fast->next) { fast = fast->next->next; slow = slow->next; if(fast == slow) { ListNode* cur = head; ListNode* meet = slow; while(cur != meet) { cur = cur->next; meet = meet->next; } return meet; } } return NULL; }