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.
staticSinglyLinkedListNodemergeLists(SinglyLinkedListNodehead1,SinglyLinkedListNodehead2){SinglyLinkedListNodehead=newSinglyLinkedListNode(0);SinglyLinkedListNodetemp=head;//temp head, use for traversalSinglyLinkedListNodenode1=head1;SinglyLinkedListNodenode2=head2;while(node1!=null&&node2!=null){if(node1.data<node2.data){temp.next=node1;node1=node1.next;}else{temp.next=node2;node2=node2.next;}temp=temp.next;}if(node1!=null){temp.next=node1;}if(node2!=null){temp.next=node2;}returnhead.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 →
Java Solution