/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* EntryNodeOfLoop(ListNode* pHead)
{
ListNode*fast = pHead;
ListNode*slow = pHead;
bool flag = 0;
while(fast != NULL)
{
if(fast->next==NULL || slow->next == NULL)
{
return NULL;
}
fast = fast->next->next;
slow = slow->next;
if(fast == slow )
{
flag= 1;
break;
}
}
if(flag == 0)
{
return NULL;
}
while(1)
{
if(slow == pHead)
{
return slow;
}
slow = slow->next;
pHead = pHead->next;
}
}
};