Search topics...

Intersection of Two Linked Lists

easy
linked-listTime: O(N)Space: O(1)Frequency: 4

Given the heads of two singly linked lists, return the node at which they intersect, or null.

Example 1:

Input: listA = [4, 1, 8, 4, 5], listB = [5, 6, 1, 8, 4, 5]
       (Intersection at node with value 8)
Output: Node with value 8

Example 2:

Input: listA = [2, 6, 4], listB = [1, 5]
       (No intersection)
Output: null
linked-list