struct ListNode *detectCycle(struct ListNode *head) {struct ListNode *fast=head;struct ListNode *slow=head;// 先用快、慢指针找到相遇点// 若相遇,则说明存在环while(fast!=NULL&&fast->next!=NULL){fast=fast->next->next;slow=slow->next;if(fast==slow){// 再找到环的入口struct ListNode *p=head;// x=(n-1)(y+z)+zwhile(p!=slow){p=p->next;slow=slow->next;}return p;}}return NULL;
}