找出环形链表的入口
注意:链表功能需要用户自己添加,本题只做调用
struct ListNode* EntryNodeOfLoop(struct ListNode* pHead ) {
// write code here
if(NULL == pHead) return NULL;
if(NULL == pHead->next) return NULL;
struct ListNode* fast = pHead->next->next;
struct ListNode* slow = pHead->next;
while(NULL != fast && NULL != fast->next)
{
if(fast == slow) break;
slow = slow->next;
fast = fast->next->next;
}
if(fast != slow) return NULL;
fast = pHead;
while(fast != slow)
{
slow = slow->next;
fast = fast->next;
}
return slow;
}