import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { public ListNode sortInList (ListNode head) { PriorityQueue<ListNode> queue=new PriorityQueue<>((o1,o2)->(o1.val-o2.val)); while(head!=null){ queue.offer(head); head=head.next; } ListNode node=new ListNode(-1); ListNode cur=node; while(!queue.isEmpty()){ ListNode list=queue.poll(); list.next=null; node.next=list; node=node.next; } return cur.next; } }