mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0142.环形链表II.md
This commit is contained in:
@ -234,6 +234,29 @@ class Solution:
|
||||
```
|
||||
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user