Merge k sorted acyclic linked lists into one sorted linked list and return its head. Empty lists are allowed.
Example 1
Argument 1, list 1: next pointers; tail points to null.
Argument 1, list 2: next pointers; tail points to null.
Argument 1, list 3: next pointers; tail points to null. No nodes or connections.Argument 1, list 4: next pointers; tail points to null.
Input
lists = [[1,6],[2,4],[],[0,8]]
Output
[0,1,2,4,6,8]
Explanation
Merge four streams, skipping the empty one, to obtain 0,1,2,4,6,8.
Example 2
Input
lists = []
Output
null
Explanation
There are no lists to merge.
Example 3
Argument 1, list 1: next pointers; tail points to null. No nodes or connections.Argument 1, list 2: next pointers; tail points to null. No nodes or connections.
Input
lists = [[],[]]
Output
null
Explanation
Several empty lists still produce an empty result.
Example 4
Argument 1, list 1: next pointers; tail points to null.
Argument 1, list 2: next pointers; tail points to null.
Input
lists = [[1,1],[1,2]]
Output
[1,1,1,2]
Explanation
All three occurrences of 1 must survive the merge, including equal values from different lists; 2 follows them.
Constraints
0 <= k <= 10000
Total number of nodes <= 10000
Each list is nondecreasing
Function contractmergeKListsArguments: list[]
Loading draft…
SolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.