Loading practice problems…
Loading your practice workspace…
Loading code editor…
22 / 29
Sign in
Algorithms/Linked List

Merge Two Sorted Lists

easy25 min

Given the heads of two sorted singly linked lists, combine their existing nodes into one sorted list.

Return the head of the merged list. Each node has the shape { val, next }.

Example 1

Inputlist1 = [1, 2, 4], list2 = [1, 3, 4]

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

Example 2

Inputlist1 = [], list2 = []

Output[]

Constraints

  • 0 ≤ total number of nodes ≤ 100
  • Both input lists are sorted in non-decreasing order.
Linked ListTwo Pointers