/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};
*/
/*
第一次十分钟解决
第一次一次性过
正式宣布,这是里程碑式的一道题!(香槟--香槟--)
*/
#include <set>
class Solution {
public:
    // 对于这道题,我的想法是将全部结点压入set中。
    // 根据set的特性,如果有重复结点压入set中时,set大小不会发生变化
    ListNode* EntryNodeOfLoop(ListNode* pHead) {
        set<ListNode*> mtset;
        ListNode* node=pHead;
        while (node!=nullptr) {
            int len=mtset.size();
            ListNode* pnext=node->next;
            mtset.insert(node);
            if (len==mtset.size()) {
                return node;
            }
            node=pnext;
        }
        return nullptr;
    }
};