You are viewing a single comment's thread. Return to all comments →
java solution static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { List numbers = new ArrayList<>(); SinglyLinkedListNode h1 = head1; while(h1 != null){ numbers.add(h1.data); h1=h1.next; } SinglyLinkedListNode h2 = head2; while(h2 != null){ numbers.add(h2.data); h2=h2.next; } Collections.sort(numbers, Comparator.reverseOrder()); SinglyLinkedListNode h3 = new SinglyLinkedListNode(numbers.get(0)); for (int i=1;i
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
java solution static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { List numbers = new ArrayList<>(); SinglyLinkedListNode h1 = head1; while(h1 != null){ numbers.add(h1.data); h1=h1.next; } SinglyLinkedListNode h2 = head2; while(h2 != null){ numbers.add(h2.data); h2=h2.next; } Collections.sort(numbers, Comparator.reverseOrder()); SinglyLinkedListNode h3 = new SinglyLinkedListNode(numbers.get(0)); for (int i=1;i