Problem Statement
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one sorted linked-list and return it.
Example 1:
| |
Example 2:
| |
Example 3:
| |
Constraints:
k == lists.length0 <= k <= 1040 <= lists[i].length <= 500-10^4 <= lists[i][j] <= 10^4lists[i]is sorted in ascending order.- The sum of
lists[i].lengthwill not exceed10^4.
Test Cases
| |
Solution
Solution 1: Python
| |
Solution 2: Python
| |
Here,
I use
countas a second member for comparison for case when tuples has samel.val- I could have used list indices as second member but they could also conflict.
- Because
countwill always be unique
Time complexity is
O(nlogk)- Breakup:
O(klogk + n+ (n-k)logk))
- Breakup: