题解 | #链表中环的入口结点#
链表中环的入口结点
https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
package main func EntryNodeOfLoop(pHead *ListNode) *ListNode { reverseHead := &ListNode{} for pHead != nil { if pHead.Next == nil { return nil } // 判断自环 if pHead.Next == pHead { return pHead } // 判断环 if pHead.Next.Next == reverseHead { return pHead.Next } temp := pHead.Next pHead.Next = reverseHead pHead = temp } return nil }