-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path160.js
More file actions
41 lines (37 loc) · 708 Bytes
/
Copy path160.js
File metadata and controls
41 lines (37 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var getIntersectionNode = function(headA, headB) {
if(!headA || !headB) return null;
let p1 = headA;
let p2 = headB;
while(p1 !== p2){
p1 = p1.next;
p2 = p2.next;
if(p1 == p2){
return p1;
}
if(p2 == null){
p2 = headA;
}
if(p1 == null){
p1 = headB;
}
}
return p1;
};
//Hash table
/*
var getIntersectionNode = function(headA, headB) {
let l1 = headA;
let l2 = headB;
let hashMap = new Map();
while(l1){
hashMap.set(l1,true)
l1 = l1.next;
}
while(l2) {
if(hashMap.has(l2)){
return l2;
}
l2 = l2.next;
}
return;
}; */