本题源自剑指offer
--------------------------------------------------------
1用俩个指针,遍历链表快指针和慢指针必定在环内相遇,然后可以让一个指针从头开始遍历,一个指针在相遇点遍历,俩个指针重合就是环的入口,
2也可以在相遇点求出环结点的个数,然后都头链表头开始遍历,让其中一个指针先走环节点步,第二个指针在出发。
ListNode* EntryNodeOfLoop(ListNode* pHead)
{
ListNode *slow = pHead;
ListNode *fast = pHead;
do{
if(fast == NULL || fast->next==NULL)
return NULL;
fast = fast->next->next;
slow = slow->next;
}while(slow != fast);
slow = pHead;
while(slow != fast){
slow = slow->next;
fast = fast->next;
}
return slow;
}