Dodomeki
Sign in

22. Merge Sorted Lists

Easy

You are given the heads of two linked lists in ascending order. Return a new list containing all values in ascending order; if there is a tie, either node may come first.

Example 1
Input: a = [1, 4, 7], b = [2, 3, 8]
Output: [1, 2, 3, 4, 7, 8]
Example 2
Input: a = [], b = [-2, 5]
Output: [-2, 5]
Constraints
  • 0 <= tamanho de cada lista <= 10000
  • Os valores de cada lista estão em ordem crescente.
Linked listTwo pointers
Caso 1
a =
[1,4,7]
b =
[2,3,8]
Expected =
[1,2,3,4,7,8]
Caso 2
a =
[]
b =
[-2,5]
Expected =
[-2,5]

Run checks these 2 cases. Submit runs all 6, including hidden ones.