添加新题目
This commit is contained in:
22
链表/环形链表2/main.go
Normal file
22
链表/环形链表2/main.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user