← 返回 snowflake 的题目列表Merge K Sorted Lists
类型:qbank
You are given an array of k linked lists lists, where each list is sorted in ascending order.
Merge K Sorted Lists
You are given an array of k linked lists lists, where each list is sorted in ascending order.
SWE
linked-list
heap
divide-and-conquer
merge
hard
Frequency
Single report
Last asked
2026-01-13
Stage
phone-screen · onsite-coding
Merge K Sorted Lists
Problem Requirements
You are provided with an array called lists. This array contains k linked lists. Each of these lists is already sorted from smallest to largest (ascending order).
Your goal is to combine all these individual linked lists into one single linked list. This final result must also be sorted. You need to return the head of this merged list.
Sample Inputs and Outputs
Case 1
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Case 2
Input: lists = []
Output: []
Case 3
Input: lists = [[]]
Output: []
Input Limits
k is the same as the length of the lists array.
k is between 0 and 10^4.
The length of any single list is between 0 and 500.
The value of any node is between -10^4 and 10^4.
Every list inside lists is already sorted in ascending order.
The total number of nodes across all lists combined will not be more than 10^4.