题目链接
思路
把全部结点放入优先队列中,然后再依次组成新链表
代码
class Solution {
public ListNode mergeKLists(ListNode[] lists) {
PriorityQueue<Integer> listNodePriorityQueue = new PriorityQueue<>();
for(int i = 0; i < lists.length; i++){
ListNode p = lists[i];
while(p != null){
listNodePriorityQueue.add(p.val);
p = p.next;
}
}
ListNode res = new ListNode();
ListNode tail = res;
while(!listNodePriorityQueue.isEmpty()){
tail.next = new ListNode(listNodePriorityQueue.poll());
tail = tail.next;
}
return res.next;
}
}
标签:ListNode,23,next,链表,tail,listNodePriorityQueue,升序
From: https://www.cnblogs.com/shixuanliu/p/17034659.html