Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Node flattenLinkedList(Node head) {
- Node tmp = head;
- PriorityQueue<Integer> pq=new PriorityQueue<>();
- while(tmp != null){
- Node tmp2 = tmp;
- while(tmp2 != null){
- pq.add(tmp2.data);
- tmp2 = tmp2.child;
- }
- tmp = tmp.next;
- }
- Node ans = new Node(100);
- tmp = ans;
- while(!pq.isEmpty()){
- int data = pq.poll();
- Node x = new Node(data);
- tmp.child = x;
- tmp = tmp.child;
- }
- return ans.child;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement