Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 655 Bytes

23.md

File metadata and controls

27 lines (23 loc) · 655 Bytes

LeetCode 23 Merge k Sorted Lists——hard

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
Example:
Input:
[
  1->4->5,
  1->3->4,
  2->6
]
Output: 1->1->2->3->4->4->5->6  
思路:
链表的合并排序
1、第一步分治法
2、第二步合并、即21题的合并函数、直接拿过来用即可
3、如果start>end、则返回null
4、如果start=end、则返回具体的一个链表lists[start]
5、然后分治法、得到l1、l2;
6、然后合并两个链表、一直递归、便得到最终的链表