Intersection of Two Lists
Find the node where two Linked Lists merge using the Two-Pointer technique.
List A (Head 1)
10
0xa1
20
0xa2
40
0xc4
50
0xc5
60
0xc6
NULL
List B (Head 2)
90
0xb1
40
0xc4
50
0xc5
60
0xc6
NULL
Status: Click 'Find Intersection' to start.
Speed:
1function getIntersectionNode(headA, headB):
2 if !headA or !headB: return null
3 pA = headA, pB = headB
4
5 while pA != pB:
6 pA = !pA ? headB : pA.next
7 pB = !pB ? headA : pB.next
8
9 return pA // or pB