u
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package top100liked
|
||||
|
||||
// https://leetcode.cn/problems/intersection-of-two-linked-lists/?envType=study-plan-v2&envId=top-100-liked
|
||||
|
||||
type ListNode struct {
|
||||
Val int
|
||||
Next *ListNode
|
||||
}
|
||||
|
||||
func getIntersectionNode(headA, headB *ListNode) *ListNode {
|
||||
vis := map[*ListNode]bool{}
|
||||
for tmp := headA; tmp != nil; tmp = tmp.Next {
|
||||
vis[tmp] = true
|
||||
}
|
||||
for tmp := headB; tmp != nil; tmp = tmp.Next {
|
||||
if vis[tmp] {
|
||||
return tmp
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user