← 返回 citadel 的题目列表Merge K Sorted Lists with Timestamps
类型:online_judge
Given a list of K sorted linked lists where each node contains a value and a timestamp, merge them into one sorted list. If timestamps are the same, merge the nodes with the same timestamp first, then merge the entire list.
Implement the function mergeKLists as follows:
def mergeKLists(lists: List[ListNode], timestamps: List[int]) -> ListNode:
# TODO: Implement the function
Parameters:
lists: A list containing K sorted linked lists.
timestamps: An array representing timestamps.
Output:
Return a merged sorted list.
Note:
Timestamps will be used for sorting nodes during the merge process.
Example
Input
[[1,2,2],[1,3,4],[2,6]]
[1,2,3]
Output
[1,1,2,2,3,4,6]