Update 0142.环形链表II.md

This commit is contained in:
QuinnDK
2021-05-17 15:50:36 +08:00
committed by GitHub
parent 8c3d8aab25
commit 6917b61c58

View File

@ -234,6 +234,29 @@ class Solution:
``` ```
Go Go
```func detectCycle(head *ListNode) *ListNode {
if head ==nil{
return head
}
slow:=head
fast:=head.Next
for fast!=nil&&fast.Next!=nil{
if fast==slow{
slow=head
fast=fast.Next
for fast!=slow {
fast=fast.Next
slow=slow.Next
}
return slow
}
fast=fast.Next.Next
slow=slow.Next
}
return nil
}
```
----------------------- -----------------------