Linked listsExplained
Intersection of Two Linked Lists
Walk both lists, switching heads at the end, so the pointers meet at the intersection.
Time
O(n + m)
Extra space
O(1)
Use it for
Finding a shared tail.
Walk both lists, switching heads at the end, so the pointers meet at the intersection.
Time
O(n + m)
Extra space
O(1)
Use it for
Finding a shared tail.