/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* EntryNodeOfLoop(ListNode* pHead) {
unordered_set<ListNode*> seen;
auto p = pHead;
while (p) {
if (seen.count(p)) return p;
seen.emplace(p);
// if (!seen.emplace(p).second) // 花花老师的代码风格 有多年的c++ 代码功底
// return p;
p = p->next;
}
return nullptr;
}
}; 


京公网安备 11010502036488号