We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Merge two sorted linked lists
- Discussions
Merge two sorted linked lists
Merge two sorted linked lists
Sort by
recency
|
42 Discussions
|
Please Login in order to post a comment
Java Solution
Java 8 - Solution
Here is Hackerrank merge two sorted linked lists problem solution in Python, Java, c++ c and javascript
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