golang leetcode 环状链表II
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func detectCycle(head *ListNode) *ListNode {
if head==nil{
return nil
}
//快慢指针
slow:=head
fast:=head
for fast!=nil&&fast.Next!=nil{
slow = slow.Next
fast = fast.Next.Next
if fast==slow{
tmp:=head
for tmp!=slow{
tmp = tmp.Next
slow = slow.Next
}
return tmp
}
}
return nil
}