Skip to content

Commit 849aeb1

Browse files
authored
Update 160-intersection-of-two-linked-lists.js
1 parent 3fbc63e commit 849aeb1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

160-intersection-of-two-linked-lists.js

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* function ListNode(val) {
4+
* this.val = val;
5+
* this.next = null;
6+
* }
7+
*/
8+
9+
/**
10+
* @param {ListNode} headA
11+
* @param {ListNode} headB
12+
* @return {ListNode}
13+
*/
14+
const getIntersectionNode = function(headA, headB) {
15+
let a = headA, b = headB
16+
while(a !== b) {
17+
a = a == null ? headB : a.next
18+
b = b == null ? headA : b.next
19+
}
20+
return a
21+
};
22+
23+
// another
24+
125
/**
226
* Definition for singly-linked list.
327
* function ListNode(val) {

0 commit comments

Comments
 (0)