https://www.nowcoder.com/practice/650474f313294468a4ded3ce0f7898b9
解决方案
Go
func hasCycle(head *ListNode) bool {
// write code here
ptr1, ptr2 := head, head
for {
if ptr2 == nil || ptr2.Next == nil {
return false
}
ptr2 = ptr2.Next.Next
ptr1 = ptr1.Next
if ptr1 == ptr2 {
break
}
}
return true
}