leetcode 160 补充js代码

pull/22/head
daluozha 2021-05-03 22:49:26 +08:00
parent c09b621628
commit 096d624df3
1 changed files with 30 additions and 0 deletions

View File

@ -79,6 +79,24 @@ public:
};
```
JS Code:
```javascript
var getIntersectionNode = function(headA, headB) {
let tempa = headA, tempb = headB
const map = new Map()
while(tempa){
map.set(tempa, 1)
tempa = tempa.next
}
while(tempb){
if(map.get(tempb))
return tempb
tempb = tempb.next
}
return tempb
};
```
@ -128,6 +146,18 @@ public:
};
```
JS Code:
```javascript
var getIntersectionNode = function(headA, headB) {
let tempa = headA, tempb = headB
while(tempa !== tempb){
tempa = tempa ? tempa.next : headB
tempb = tempb ? tempb.next : headA
}
return tempa
};
```