Search⌘ K
AI Features

Solution: Intersection of Two Linked Lists

Understand how to determine if two singly linked lists intersect and find the intersection node using an efficient two-pointer technique. This lesson teaches a method that aligns pointers without length calculation, enabling traversal in linear time with constant space. Learn to apply this approach to solve linked list intersection problems confidently.

Statement

You are given the heads of two singly linked lists, headA and headB, to determine whether the two lists intersect. If they intersect, return the node where the intersection begins. Otherwise, return NULL.

Note: Linked lists intersect if they share a common node in memory, not just a node with the same value.

Constraints:

  • 11 ≤ node.val 105≤ 10^5

  • The number of nodes of listAlistA is in the mm.

  • The number of nodes of listBlistB is in the nn ...