File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 99
99
149|[ Max Points on a Line] ( ./0149-max-points-on-a-line.js ) |Hard|
100
100
151|[ Reverse Words in a String] ( ./0151-reverse-words-in-a-string.js ) |Medium|
101
101
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|
102
103
167|[ Two Sum II - Input Array Is Sorted] ( ./0167-two-sum-ii-input-array-is-sorted.js ) |Easy|
103
104
169|[ Majority Element] ( ./0169-majority-element.js ) |Easy|
104
105
179|[ Largest Number] ( ./0179-largest-number.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments