/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead) {
//遍历链表 map存储每个节点出现的次数 返回重复出现的第一个节点
        unordered_map<ListNode*, int> m;
        while(pHead != nullptr)
        {
            if(m[pHead] == 1)
                return pHead;
            m[pHead]++;
            pHead = pHead->next;
        }
        return nullptr;
    }
};