/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; */ class Solution { public: ListNode* EntryNodeOfLoop(ListNode* pHead) { if(pHead==NULL) return NULL; ListNode * p, * q; p=pHead,q=pHead; while(q!=NULL&&q->next!=NULL) { p=p->next; q=q->next->next; if(p==q) break; } if(q==NULL||q->next==NULL) return NULL; p=pHead; while(p!=q) { p=p->next; q=q->next; } return p; } };