题解 | #c++ 5行哈希表搞定 链表环节点入口#
链表中环的入口结点
http://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
ListNode* EntryNodeOfLoop(ListNode* pHead) {
unordered_set<ListNode*> Nodes;
while(pHead && !Nodes.count(pHead)){
Nodes.insert(pHead);
pHead = pHead->next;
}
return pHead;
}
};