dsa · easy

Merge Two Sorted Lists

You are given the heads of two sorted singly linked lists. Merge them into one sorted list and return the new head. Empty lists are allowed; merging with empty is the other list.

Arguments

Walk .next on each ListNode. The judge prints the resulting values.

Example

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

Constraints

0 <= lengths <= 50

Examples

Example 1

Input:
[1,2,4]
[1,3,4]

Expected:
[1,1,2,3,4,4]

Example 2

Input:
[]
[]

Expected:
[]

Open in the Dojo editor