题解 | #链表中环的入口结点#
链表中环的入口结点
http://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
题解: ##方法一## 快慢指针法 : 使用找到环的方法 先让快慢指针相遇 有可能是在环内相遇 策略是 while (slow != fast) slow = slow->next; fast=fast->next; if(slow==fast) return slow
##方法二## set集合方法 unordered_set<ListNode*> st; st.insert(pHead); pHead = pHead->next; if (st.find(pHead) == st.end()) return pHead;