{ "data": { "question": { "questionId": "1000342", "questionFrontendId": "剑指 Offer II 078", "categoryTitle": "LCOF2", "boundTopicId": 910336, "title": "合并排序链表", "titleSlug": "vvXgSW", "content": "
English description is not available for the problem. Please switch to Chinese.
\n", "translatedTitle": "合并排序链表", "translatedContent": "给定一个链表数组,每个链表都已经按升序排列。
\n\n请将所有链表合并到一个升序链表中,返回合并后的链表。
\n\n\n\n
示例 1:
\n\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\n输入:lists = []\n输出:[]\n\n\n
示例 3:
\n\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
\n\n
注意:本题与主站 23 题相同: https://leetcode-cn.com/problems/merge-k-sorted-lists/
\n", "isPaidOnly": false, "difficulty": "Hard", "likes": 37, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [ { "username": "LeetCode", "profileUrl": "/u/leetcode", "avatarUrl": "https://assets.leetcode-cn.com/aliyun-lc-upload/uploaded_files/2021/03/73c9f099-abbe-4d94-853f-f8abffd459cd/leetcode.png", "__typename": "ContributorNode" } ], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": true, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Linked List", "slug": "linked-list", "translatedName": "链表", "__typename": "TopicTagNode" }, { "name": "Divide and Conquer", "slug": "divide-and-conquer", "translatedName": "分治", "__typename": "TopicTagNode" }, { "name": "Heap (Priority Queue)", "slug": "heap-priority-queue", "translatedName": "堆(优先队列)", "__typename": "TopicTagNode" }, { "name": "Merge Sort", "slug": "merge-sort", "translatedName": "归并排序", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "C++", "langSlug": "cpp", "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n ListNode* mergeKLists(vector