Quiz
#160 Intersection of Two Linked Lists
APPROACH
Given the heads of two singly linked lists headA and headB, find and return the node where the two lists first intersect. If they never meet, return null.
The lists have no cycles and must remain unchanged after the function returns.
Custom Judge:
The inputs to the judge are given as follows (your program is not given these inputs):
- intersectVal — the value at the intersection node, or 0 if there is none.
- listA — the first linked list.
- listB — the second linked list.
- skipA — the number of nodes to skip in listA from the head to reach the intersection.
- skipB — the number of nodes to skip in listB from the head to reach the intersection.
If you return the correct intersecting node, the solution is accepted.
Example 1:
Example 2:
Example 3:
What is the optimal approach for this problem?