Merge k Sorted Lists

Hard

Topics
Linked ListHeapDivide and ConquerMerge Sort

You are given an array of k sorted linked lists. Merge them into one sorted list and return its head.

Example 1

Input:  lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]

Example 2

Input:  lists = []
Output: []

Constraints

  • 0 <= k <= 10^4
  • 0 <= list length <= 500
  • Each list is sorted non-decreasing.
Run ⌘' · Submit ⌘⏎