Files
Hot-100-Algorithm/链表/环形链表2/main.go
2025-08-23 23:09:54 +08:00

23 lines
308 B
Go

package main
type ListNode struct {
Val int
Next *ListNode
}
func main() {
}
func detectCycle(head *ListNode) *ListNode {
hash := make(map[*ListNode]struct{})
for head != nil {
if _, ok := hash[head.Next]; ok {
return head.Next
}
hash[head] = struct{}{}
head = head.Next
}
return nil
}