#21

Merge Two Sorted Lists

pupil · 310 · lc easy +21 · verified · 68% accepted · 24,817 likes · top 75%

play →

Description

Merge sorted linked lists list1 and list2 by relinking their existing nodes into one ascending list. Return the new head.

Example 1:

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

Example 2:

Input: list1 = [], list2 = []
Output: []

Example 3:

Input: list1 = [], list2 = [0]
Output: [0]

Code

1
2
3
4
5
6
7
8