ASAPUtils Logo ASAPUtils
Week 5

Merge Two Sorted Lists

Merge Two Sorted Lists with the dummy-head and moving-tail pattern, including the sorted-prefix invariant, C++ and JavaScript implementations, complexity, edge cases, and a two-list interactive trace.

The problem

Given the heads of two nondecreasing linked lists, splice their nodes into one nondecreasing list and return its head.

1 -> 2 -> 4 and 1 -> 3 -> 4 become 1 -> 1 -> 2 -> 3 -> 4 -> 4

Related Problems