Advertisement
enigmjoe

Big O week 3 day 6 p2

Sep 2nd, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. public static Node flattenLinkedList(Node head) {
  2. Node tmp = head;
  3. PriorityQueue<Integer> pq=new PriorityQueue<>();
  4. while(tmp != null){
  5. Node tmp2 = tmp;
  6. while(tmp2 != null){
  7. pq.add(tmp2.data);
  8. tmp2 = tmp2.child;
  9. }
  10. tmp = tmp.next;
  11. }
  12. Node ans = new Node(100);
  13. tmp = ans;
  14. while(!pq.isEmpty()){
  15. int data = pq.poll();
  16. Node x = new Node(data);
  17. tmp.child = x;
  18. tmp = tmp.child;
  19. }
  20. return ans.child;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement