Skip to content

Instantly share code, notes, and snippets.

@ZackFox
Last active February 24, 2021 12:19
Show Gist options
  • Save ZackFox/b6dca80f7a3859f6717e0e1b00bd31c7 to your computer and use it in GitHub Desktop.
Save ZackFox/b6dca80f7a3859f6717e0e1b00bd31c7 to your computer and use it in GitHub Desktop.
/**
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
var mergeTwoLists = function(l1, l2) {
const dummy = new ListNode(0);
let current = dummy;
while(l1 !== null && l2 !== null){
if(l1.val <= l2.val){
current.next = l1;
l1 = l1.next;
} else{
current.next = l2;
l2 = l2.next;
}
current = current.next;
}
if(l1 !== null){
current.next = l1;
}
if(l2 !== null){
current.next = l2;
}
return dummy.next;
};
@herberthk
Copy link

Thanks it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment