You are viewing a single comment's thread. Return to all comments →
JS
function mergeLists(head1, head2) { const list = []; while (head1) { list.push(head1.data); head1 = head1.next; } while (head2) { list.push(head2.data); head2 = head2.next; } list.sort((a, b) => a - b); const head = new SinglyLinkedListNode(list[0]); list.reduce((node, value, index) => { if (index) { node.next = new SinglyLinkedListNode(value); node = node.next; } return node; }, head); return head; }
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 →
JS