Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Latest commit

 

History

History

0023.merge-k-sorted-lists

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

题目

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

解题思路

最先想到的方案是,依次合并res=merge(res, lists[i]),这个方案的坏处是需要合并两个长度相差很大的链。 LeetCode上最快的解决方法是,借鉴了归并排序的思想,让lists中临近的list先两两合并,再让新生成的lists中的临近list两两合并,直到合并完成。

总结