Problem
You get an array lists of k linked lists, and each list is sorted in ascending order. Merge them all into one sorted linked list and return its head. Any of the lists may be empty, and so may the array itself.
Example 1
- Input
- lists = [1
- Output
- 4 -> 5, 1 -> 3 -> 4, 2 -> 6] → 1 -> 1 -> 2 -> 3 -> 4 -> 4 -> 5 -> 6
Example 2
- Input
- lists = []
- Output
- (empty)
Example 3
- Input
- lists = [(empty)]
- Output
- (empty)
The tests pass lists as an array of list heads.
Constraints
0 <= k <= 10^40 <= length of each list <= 500-10^4 <= Node.val <= 10^4The total number of nodes is at most 10^4.