Skip to content

Commit b5cede9

Browse files
committedJan 15, 2023
Add solution #160
1 parent 7395d01 commit b5cede9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
149|[Max Points on a Line](./0149-max-points-on-a-line.js)|Hard|
100100
151|[Reverse Words in a String](./0151-reverse-words-in-a-string.js)|Medium|
101101
152|[Maximum Product Subarray](./0152-maximum-product-subarray.js)|Medium|
102+
160|[Intersection of Two Linked Lists](./0160-intersection-of-two-linked-lists.js)|Medium|
102103
167|[Two Sum II - Input Array Is Sorted](./0167-two-sum-ii-input-array-is-sorted.js)|Easy|
103104
169|[Majority Element](./0169-majority-element.js)|Easy|
104105
179|[Largest Number](./0179-largest-number.js)|Medium|
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* 160. Intersection of Two Linked Lists
3+
* https://leetcode.com/problems/intersection-of-two-linked-lists/
4+
* Difficulty: Medium
5+
*
6+
* Given the heads of two singly linked-lists headA and headB, return the
7+
* node at which the two lists intersect. If the two linked lists have no
8+
* intersection at all, return null.
9+
*
10+
* For example, the following two linked lists begin to intersect at node c1:
11+
*/
12+
13+
/**
14+
* Definition for singly-linked list.
15+
* function ListNode(val) {
16+
* this.val = val;
17+
* this.next = null;
18+
* }
19+
*/
20+
21+
/**
22+
* @param {ListNode} headA
23+
* @param {ListNode} headB
24+
* @return {ListNode}
25+
*/
26+
var getIntersectionNode = function(headA, headB) {
27+
if (!headA || !headB) {
28+
return null;
29+
}
30+
31+
let a = headA;
32+
let b = headB;
33+
34+
while (a !== b) {
35+
a = a === null ? headB : a.next;
36+
b = b === null ? headA : b.next;
37+
}
38+
39+
return a;
40+
};

0 commit comments

Comments
 (0)
Please sign in to comment.