牛客题霸 NC3 链表中环的入口结点
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC3 链表中环的入口结点
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/253d2c59ec3e4bc68da16833f79a38e4
解決方案
Go
func EntryNodeOfLoop(pHead *ListNode) *ListNode {ptr1, ptr2 := pHead, pHeadfor {if ptr2 == nil || ptr2.Next == nil {return nil}ptr2 = ptr2.Next.Nextptr1 = ptr1.Nextif ptr1 == ptr2 {break}}for ptr2 = pHead; ptr1 != ptr2; {ptr2 = ptr2.Nextptr1 = ptr1.Next}return ptr1 }參考文章
總結
以上是生活随笔為你收集整理的牛客题霸 NC3 链表中环的入口结点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客题霸 NC2 重排链表
- 下一篇: 牛客题霸 NC4 判断链表中是否有环