题解 | #链表中环的入口结点#
链表中环的入口结点
http://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
package main //双指针法 func EntryNodeOfLoop(pHead *ListNode) *ListNode{ if pHead == nil || pHead.Next == nil { return nil } fast , slow := pHead, pHead for fast != nil && fast.Next.Next != nil { fast = fast.Next.Next slow = slow.Next if fast == slow { tmp := pHead for tmp != slow { tmp = tmp.Next slow = slow.Next } return tmp } } return nil }