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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Linked Lists problems