Search for a command to run...
Traverse both lists; redirecting pointers to opposite heads aligns distances to intersection
Initialization
d1 is at head of List A (1). d2 is at head of List B (3).
Pointer Redirection
1class Solution {2 getIntersectionNode(headA, headB) {3 if (headA === null || headB === null) return null;4 5 let d1 = headA, d2 = headB;6 7 while (d1 !== d2) {8 d1 = d1 ? d1.next : headB;9 d2 = d2 ? d2.next : headA;10 }11 12 return d1;//d1: 1d2: 313 }14}