Skip to main content

Merge Two Sorted Lists

EasyLinked Lists

Merge two sorted linked lists into one sorted list. The list is represented as a nested object: { val: 1, next: { val: 2, next: null } }

Example:

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

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

Constraints:

  • 0 <= list length <= 50
  • -100 <= Node.val <= 100
  • Both lists are sorted in non-decreasing order