Skip to content

Instantly share code, notes, and snippets.

@rahul4coding
Created December 16, 2019 19:24
Show Gist options
  • Save rahul4coding/4670a28083b404de4f4d543357546547 to your computer and use it in GitHub Desktop.
Save rahul4coding/4670a28083b404de4f4d543357546547 to your computer and use it in GitHub Desktop.
merge two sorted Linked list
function mergeLists(head1, head2) {
var result = new SinglyLinkedListNode();
// case1
if(head1==null){
return head2;
}else if(head2==null){
return head1;
}
//case 2
if(head1.data <= head2.data){
result = head1;
result.next = mergeLists(head1.next,head2)
}else{
result = head2;
result.next = mergeLists(head1, head2.next)
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment