题解 | #链表中环的入口结点#
链表中环的入口结点
http://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
/* 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; } };