添加新题目
This commit is contained in:
28
链表/相交链表/main.go
Normal file
28
链表/相交链表/main.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
type ListNode struct {
|
||||
Val int
|
||||
Next *ListNode
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
func getIntersectionNode(headA, headB *ListNode) *ListNode {
|
||||
Anode, Bnode := headA, headB
|
||||
hash := make(map[*ListNode]struct{})
|
||||
|
||||
for Anode != nil {
|
||||
hash[Anode] = struct{}{}
|
||||
Anode = Anode.Next
|
||||
}
|
||||
for Bnode != nil {
|
||||
if _, ok := hash[Bnode]; ok {
|
||||
return Bnode
|
||||
}
|
||||
Bnode = Bnode.Next
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user