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