Intersection node of two linked lists

Problem Given the heads of two singly linked lists that may merge at some node, return the node where they intersect, or null if they never do.

Input / Output

  • Input: heads of lists A and B.
  • Output: the first shared node, or null.

Constraints

  • The lists may or may not intersect.
  • Aim for O(m + n) time and O(1) space.

Example

A: a1 -> a2 -> c1 -> c2 -> c3
B:       b1 -> c1 -> c2 -> c3
intersection -> c1
asked …
LeaderboardSalaryAccount