/**
* 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;
auto i=head,j=head;
do
{
i=i->next;
if(j->next&&j->next->next) j=j->next->next;
else return NULL;
}while(i!=j);
j=head;
while(i!=j)
{
i=i->next;
j=j->next;
}
return i;
}
};
标签:II,head,ListNode,return,next,链表,142,NULL
From: https://www.cnblogs.com/tangxibomb/p/17518936.html