环形链表ll
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode *detectCycle(struct ListNode *head) {
int con=0;struct ListNode *f=head,*s=head;
for(;f&&f->next;)
{s=s->next,f=f->next->next;if(f==s){con=1;break;}}
if (con) {
s = head;
while (s != f) {
s= s->next;
f = f->next;
}
return s;
}else return NULL;
}
这道题比环形链表那道题难多了。至少方法方面要有突破,里面的数学关系很巧妙,还是要多积累才行。