Merge Two Sorted Lists
Merge two nondecreasing singly linked lists and return the head of a nondecreasing list containing every node value.
Example 1
list1 = [1,4,4]
list2 = [2,3][1,2,3,4,4]Explanation
Merge both streams while retaining both occurrences of 4.
Example 2
list1 = []
list2 = [8][8]Explanation
The first list is empty, so the second list supplies the sole node 8.
Example 3
list1 = []
list2 = []nullExplanation
Two empty lists merge into an empty list.
Constraints
- 0 <= total nodes <= 10000
- Inputs are acyclic lists encoded as value arrays
Function contract
mergeTwoListsArguments: list, listSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[1,4,4][2,3]