The problem. Given the heads of two singly linked lists, headA and headB, return the node where the two lists join. If they never join, return null. Joining means sharing the same node in memory — from that node on, both lists are identical.
Input: A = [4, 1, 8, 4, 5], B = [5, 6, 1, 8, 4, 5], they meet at the node 8
Output: the node 8
Input: A = [2, 6, 4], B = [1, 5], no shared nodes
Output: nullCareful: both lists contain a 1, but those are different nodes. We compare node identity (a === b), never values.
Free account
Sign up to read the rest of this lesson: 5 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come