← 返回 amazon 的题目列表Merge k Sorted Linked Lists into One Sorted List
类型:online_judge
amazon
Merge k Sorted Lists
You are given an array of k linked lists, each linked-list is sorted in ascending order. Merge all the linked lists into one sorted linked list and return its head.
Input:
An array of k linked lists, where each linked list is defined by a ListNode class. The ListNode has two properties: val (integer) and next (points to the next ListNode or null). The number of linked lists k satisfies: 0 <= k <= 100.
The number of nodes in the lists satisfies: 0 <= number of nodes <= 100.
Output:
Return the head of the merged sorted linked list.
Example Test Cases:
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: []
Example 3:
Input: lists = [[]]
Output: []
Example
Input
[[1,4,5],[1,3,4],[2,6]]