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.
functionmergeLists(head1,head2){letnewnode=newSinglyLinkedListNode(0,null)lettempnode=newnodewhile(head1!==null&&head2!==null){if(head1.data<head2.data){tempnode.next=head1head1=head1.next//inc of head1 linked list}else{tempnode.next=head2head2=head2.next//inc of head2 linked list}tempnode=tempnode.next//inc of newnode}tempnode.next=head1||head2// if either head1 is null then tempnode will update with head2 or vice-versareturnnewnode.next}
Cookie support is required to access HackerRank
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 →
javascript: