Practice Intersection of Two Linked Lists
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Return the first node shared by the linked lists headed by headA and headB, or null when they do not intersect. Sharing means node identity, not equal values. The lists are acyclic and their structure must remain unchanged. Judge inputs listA and listB describe values; skipA and skipB count nodes before the shared node, and intersectVal is its value or 0 when absent. Your function receives only the two heads. Follow-up: achieve O(m + n) time with O(1) extra memory.
Source: Intersection of Two Linked Lists on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
intersectVal = 8, listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3
Intersected at '8'
# Example 2
intersectVal = 2, listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
Intersected at '2'
# Example 3
intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
No intersection
Constraints
Related LeetCode Problems
Practice more problems similar to Intersection of Two Linked Lists.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.