You are viewing a single comment's thread. Return to all comments →
function mergeLists(head1, head2) { let newNode = new SinglyLinkedListNode(); let tail = newNode;
while(head1 !==null && head2 !== null){ if(head1.data < head2.data){ tail.next = head1; head1= head1.next; }else if(head2.data <= head1.data){ tail.next = head2; head2 = head2.next; } tail = tail.next; if(head1 !==null){ tail.next = head1; }else if(head2 !== null){ tail.next = head2; } } return newNode.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 →
function mergeLists(head1, head2) { let newNode = new SinglyLinkedListNode(); let tail = newNode;
}