Merge Two Sorted Lists

Merge two sorted linked lists and return it as a new sorted list. The new list should be made by splicing together the nodes of the given lists. Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Explanation: Merge the nodes while maintaining sorted order. Pattern focus: Merge Two Sorted Lists (simple pointer merge).

Input Format

list1 = ListNode, list2 = ListNode

Output Format

return ListNode

Constraints

  • The number of nodes in each list is in [0, 50].
  • -100 <= Node.val <= 100

Examples

Example 1:

Input:

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

Output:

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

Explanation:

Merged sorted order from both lists.

Loading...
Merge Two Sorted Lists - Linked List DSA Problem