cheetcode

36. Merge Two Sorted ListsEasy

Merge two sorted linked lists into one sorted list.

You are given the heads of two sorted linked lists list1 and list2.

Merge the two lists into one sorted list and return its head.

For the Cheetcode runner, linked lists are represented as plain arrays in node order.

Work with node references instead of array indexes. Make sure you preserve the next pointers you still need before changing links.

Examples

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

Constraints

  • The number of nodes in both lists is in the range [0, 50].
  • -100 <= Node.val <= 100
  • Both lists are sorted in non-decreasing order.