LeetCode 23 - Merge k Sorted Lists
题目
Merge k Sorted Lists
[HARD]
Given k sorted linked lists, merge them into one sorted linked list and return it.
Example 1:
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Explanation: The linked-lists are:
[
1->4->5,
1->3->4,
2->6
]
merging them into one sorted list:
1->1->2->3->4->4->5->6
思路
priority queue (min heap)
代码
1 | class Solution { |
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.