← All problems

Merge Two Sorted Lists

easy

You're given the heads of two sorted linked lists list1 and list2. Merge them into one sorted list by splicing the existing nodes together, and return its head.

This is the linked-list version of the merge step in Merge sort.

Example

Input: list1 = [1, 2, 4], list2 = [1, 3, 4]
Output: [1, 1, 2, 3, 4, 4]
Loading...