File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
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 aend = null
16
+ let bend = null
17
+ let ahead = headA
18
+ let bhead = headB
19
+ while ( headA !== null && headB !== null ) {
20
+ if ( aend !== null && bend !== null && aend !== bend ) {
21
+ return null
22
+ }
23
+
24
+ if ( headA === headB ) {
25
+ return headA
26
+ }
27
+
28
+ if ( headA . next === null ) {
29
+ if ( aend === null ) {
30
+ aend = headA
31
+ }
32
+ headA = bhead
33
+ } else {
34
+ headA = headA . next
35
+
36
+ }
37
+ if ( headB . next === null ) {
38
+ if ( bend === null ) {
39
+ bend = headB
40
+ }
41
+ headB = ahead
42
+ } else {
43
+ headB = headB . next
44
+ }
45
+
46
+ }
47
+
48
+ } ;
You can’t perform that action at this time.
0 commit comments