1.题目描述
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
合并 k 个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。
Example:
Input:
[
1->4->5,
1->3->4,
2->6
]
Output: 1->1->2->3->4->4->5->6
2.Solutions
迭代、分治版本:
1 | public static ListNode mergeKLists(ListNode[] lists){ |
优先队列:
If someone understand how priority queue works, then it would be trivial to walk through the codes.
1 | public ListNode mergeKLists(List<ListNode> lists) { |