You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution
static SinglyLinkedListNode mergeLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) { SinglyLinkedListNode mergedLists = new SinglyLinkedListNode(0); SinglyLinkedListNode current = mergedLists; while (head1 != null && head2 != null) { if (head1.data <= head2.data) { current.next = head1; head1 = head1.next; } else { current.next = head2; head2 = head2.next; } current = current.next; } if (head1 != null) { current.next = head1; } else { current.next = head2; } return mergedLists.next; }
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 →
My Java 8 Solution