Nav: << previous: 22.括号生成 | next: 24.两两交换链表中的节点 >>
Description
tab: English
<p>You are given an array of <code>k</code> linked-lists <code>lists</code>, each linked-list is sorted in ascending order.</p>
<p><em>Merge all the linked-lists into one sorted linked-list and return it.</em></p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> lists = [[1,4,5],[1,3,4],[2,6]]
<strong>Output:</strong> [1,1,2,3,4,4,5,6]
<strong>Explanation:</strong> The linked-lists are:
[
1->4->5,
1->3->4,
2->6
]
merging them into one sorted linked list:
1->1->2->3->4->4->5->6
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> lists = []
<strong>Output:</strong> []
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> lists = [[]]
<strong>Output:</strong> []
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>k == lists.length</code></li>
<li><code>0 <= k <= 10<sup>4</sup></code></li>
<li><code>0 <= lists[i].length <= 500</code></li>
<li><code>-10<sup>4</sup> <= lists[i][j] <= 10<sup>4</sup></code></li>
<li><code>lists[i]</code> is sorted in <strong>ascending order</strong>.</li>
<li>The sum of <code>lists[i].length</code> will not exceed <code>10<sup>4</sup></code>.</li>
</ul>
---
[submissions](https://leetcode.com/problems/merge-k-sorted-lists/submissions/) | [solutions](https://leetcode.com/problems/merge-k-sorted-lists/solutions/)
tab: 中文
<p>给你一个链表数组,每个链表都已经按升序排列。</p>
<p>请你将所有链表合并到一个升序链表中,返回合并后的链表。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre><strong>输入:</strong>lists = [[1,4,5],[1,3,4],[2,6]]
<strong>输出:</strong>[1,1,2,3,4,4,5,6]
<strong>解释:</strong>链表数组如下:
[
1->4->5,
1->3->4,
2->6
]
将它们合并到一个有序链表中得到。
1->1->2->3->4->4->5->6
</pre>
<p><strong>示例 2:</strong></p>
<pre><strong>输入:</strong>lists = []
<strong>输出:</strong>[]
</pre>
<p><strong>示例 3:</strong></p>
<pre><strong>输入:</strong>lists = [[]]
<strong>输出:</strong>[]
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>k == lists.length</code></li>
<li><code>0 <= k <= 10^4</code></li>
<li><code>0 <= lists[i].length <= 500</code></li>
<li><code>-10^4 <= lists[i][j] <= 10^4</code></li>
<li><code>lists[i]</code> 按 <strong>升序</strong> 排列</li>
<li><code>lists[i].length</code> 的总和不超过 <code>10^4</code></li>
</ul>
---
[提交记录](https://leetcode.cn/problems/merge-k-sorted-lists/submissions/) | [题解](https://leetcode.cn/problems/merge-k-sorted-lists/solution/)
Solutions & Notes
properties:
note.updated:
displayName: Last Updated
note.relative_links:
displayName: Related Links
note.desc:
displayName: Description
note.grade:
displayName: Rating
note.program_language:
displayName: Language
note.time_complexity:
displayName: TC
note.space_complexity:
displayName: SC
views:
- type: table
name: Solutions & Notes
filters:
and:
- file.hasLink(this.file)
- file.tags.containsAny("leetcode/solution", "leetcode/note")
order:
- file.name
- desc
- program_language
- time_complexity
- space_complexity
- grade
- relative_links
- updated
sort:
- property: grade
direction: ASC
- property: time_complexity
direction: ASC
- property: program_language
direction: ASC
columnSize:
file.name: 104
note.space_complexity: 65
note.grade: 126
Similar Problems
properties:
note.lcTopics:
displayName: Topics
note.lcAcRate:
displayName: AC Rate
note.favorites:
displayName: Favorites
note.grade:
displayName: Rating
note.translatedTitle:
displayName: Title (CN)
note.lcDifficulty:
displayName: Difficulty
views:
- type: table
name: Similar Problems
filters:
and:
- file.hasLink(this.file)
- similarQuestions.contains(this.file)
order:
- file.name
- translatedTitle
- lcTopics
- lcDifficulty
- lcAcRate
- grade
- favorites
sort:
- property: file.name
direction: ASC
- property: lcTopics
direction: DESC
columnSize:
note.translatedTitle: 240
note.lcTopics: 347
note.lcAcRate: 75
note.grade: 122