Merge pull request #160 from QuinnDK/添加0142环形链表IIGo版本

添加0142环形链表IIGo版本
This commit is contained in:
Carl Sun
2021-05-17 16:01:00 +08:00
committed by GitHub

View File

@ -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
}
```
-----------------------