Easy · Linked Lists

Merge two sorted lists

Given the heads of two linked lists l1 and l2, each sorted in non-decreasing order, splice their nodes together into one sorted linked list and return its head.

Examples

Example 1

[1,2,4] + [1,3,4]

Output: [1,1,2,3,4,4]

Example 2

[1,3,5,7] + [2,4]

Output: [1,2,3,4,5,7]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Linked Lists problems