/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* EntryNodeOfLoop(ListNode* pHead)
{
unordered_map<ListNode*,int>hash;
ListNode*p=pHead;
while(p)
{
if(hash.count(p)==0)
{
hash[p]=1;
}
else
{
hash[p]++;
}
if(hash[p]==2)
{
return p;
}
p=p->next;
}
return NULL;
}
};



京公网安备 11010502036488号