- Pattern: When using
2-pointer, let one pointer
moves firstcan have some surprising results.
- Get the lengths of two linked lists.
- Create two pointers, let the pointer pointing to the longest list moves
diffsteps (Diff = | lengthA - lengthB |).
pointerA === pointerB, we got the result!
Given two (singly) linked lists, determine if the two lists intersect. Return the inter secting node. Note that the intersection is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference) as the jth node of the second linked list, then they are intersecting.
Input: intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3