题目描述:
解析:优先级队列
class Solution {
public ListNode sortList(ListNode head) {
ListNode dummy = new ListNode(0);
ListNode curr = dummy;
PriorityQueue<ListNode> priorityQueue = new PriorityQueue<>((o1, o2) -> o1.val-o2.val);
while (head != null) {
priorityQueue.offer(new ListNode(head.val));
head = head.next;
}
while (!priorityQueue.isEmpty()) {
curr.next = priorityQueue.poll();
curr=curr.next;
}
return dummy.next;
}
}