{ "data": { "question": { "questionId": "23", "questionFrontendId": "23", "categoryTitle": "Algorithms", "boundTopicId": 1087, "title": "Merge k Sorted Lists", "titleSlug": "merge-k-sorted-lists", "content": "
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.
\n\n\n
Example 1:
\n\n\nInput: lists = [[1,4,5],[1,3,4],[2,6]]\nOutput: [1,1,2,3,4,4,5,6]\nExplanation: The linked-lists are:\n[\n 1->4->5,\n 1->3->4,\n 2->6\n]\nmerging them into one sorted list:\n1->1->2->3->4->4->5->6\n\n\n
Example 2:
\n\n\nInput: lists = []\nOutput: []\n\n\n
Example 3:
\n\n\nInput: lists = [[]]\nOutput: []\n\n\n
\n
Constraints:
\n\nk == lists.length
0 <= k <= 104
0 <= lists[i].length <= 500
-104 <= lists[i][j] <= 104
lists[i]
is sorted in ascending order.lists[i].length
will not exceed 104
.给你一个链表数组,每个链表都已经按升序排列。
\n\n请你将所有链表合并到一个升序链表中,返回合并后的链表。
\n\n\n\n
示例 1:
\n\n输入:lists = [[1,4,5],[1,3,4],[2,6]]\n输出:[1,1,2,3,4,4,5,6]\n解释:链表数组如下:\n[\n 1->4->5,\n 1->3->4,\n 2->6\n]\n将它们合并到一个有序链表中得到。\n1->1->2->3->4->4->5->6\n\n\n
示例 2:
\n\n输入:lists = []\n输出:[]\n\n\n
示例 3:
\n\n输入:lists = [[]]\n输出:[]\n\n\n
\n\n
提示:
\n\nk == lists.length
0 <= k <= 10^4
0 <= lists[i].length <= 500
-10^4 <= lists[i][j] <= 10^4
lists[i]
按 升序 排列lists[i].length
的总和不超过 10^4