题目描述:
    image.png
    解析:优先级队列

    1. class Solution {
    2. public ListNode sortList(ListNode head) {
    3. ListNode dummy = new ListNode(0);
    4. ListNode curr = dummy;
    5. PriorityQueue<ListNode> priorityQueue = new PriorityQueue<>((o1, o2) -> o1.val-o2.val);
    6. while (head != null) {
    7. priorityQueue.offer(new ListNode(head.val));
    8. head = head.next;
    9. }
    10. while (!priorityQueue.isEmpty()) {
    11. curr.next = priorityQueue.poll();
    12. curr=curr.next;
    13. }
    14. return dummy.next;
    15. }
    16. }