/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; */ #include <unordered_set> class Solution { public: ListNode* EntryNodeOfLoop(ListNode* pHead) { std::unordered_set<ListNode*> visited; while(pHead) { if(visited.find(pHead)!=visited.end()) { return pHead; } visited.insert(pHead); pHead=pHead->next; } return nullptr; } };