← 返回 apple 的题目列表Intersection of Two Linked Lists
类型:qbank
Given the heads of two singly linked lists headA and headB, return the node at which the two lists intersect. If the two lists have no intersection, return null.
Examples
Example 1:
Input: listA = [4,1,8,4,5], listB = [5,6,1,8,4,5], skipA = 2, skipB = 3
Output: 8
Explanation:
The two lists share the tail [8,4,5]. The first shared node has value 8.
Example 2:
Input: listA = [1,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
Output: 2
Explanation:
Shared tail [2,4]. Intersection node has value 2.
Example 3:
Input: listA = [2,6,4], listB = [1,5], skipA = -1, skipB = -1
Output: null
Explanation:
No intersection.
Constraints
0 <= listA.length, listB.length <= 3 * 10^4
1 <= Node.val <= 10^5
0 <= skipA <= listA.length or skipA == -1
0 <= skipB <= listB.length or skipB == -1