题解 | #判断链表中是否有环#
判断链表中是否有环
https://www.nowcoder.com/practice/650474f313294468a4ded3ce0f7898b9
package main import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ func hasCycle(head *ListNode) bool { p := head q := head for p != nil && q != nil { p = p.Next q = q.Next if q != nil { q = q.Next } if q != nil && p == q { return true } } return false // write code here }