添加新题目

This commit is contained in:
2025-08-23 23:09:54 +08:00
parent 62034548cc
commit 70fe6d292c
8 changed files with 260 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
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
}