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

24 lines
298 B
Go

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