0023. Merge k Sorted Lists
Hard | Linked List + Sort | 76 ms (98.81%), 22.3 MB (39.22%)
Source: LeetCode - Merge k Sorted Lists GitHub: Solution / Performance
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.
Extended question from LeetCode 0021. Merge Two Sorted Lists.
We could use the "Merge with Divide and Conquer" method for better performance. Generally speaking, we do merge starting with 2 lists per iteration, then increasing to 4 lists per iteration, etc.
Last updated