struct ListNode* EntryNodeOfLoop(struct ListNode* pHead )
{
if (pHead == NULL)
return NULL;
struct ListNode* fast = pHead;
struct ListNode* slow = pHead;
while(fast != NULL && fast->next != NULL)
{
slow = slow->next;
fast = fast->next->next;
if(slow == fast)
break;
}
if(fast == NULL || fast->next == NULL)
return NULL;
fast = pHead;
while(fast != slow)
{
fast = fast->next;
slow = slow->next;
}
return fast;
}

京公网安备 11010502036488号