Is there a way to execute the linked list programs on my local machine? I am able to run this code in their input field, but I'm having trouble running it on my local machine.
function ListNode(val, next) {
this.val = (val===undefined ? 0 : val)
this.next = (next===undefined ? null : next)
}
/**
* @param {ListNode} list1
* @param {ListNode} list2
* @return {ListNode}
*/
var mergeTwoLists = function (l1, l2) {
var mergedHead = { val: -1, next: null },
crt = mergedHead;
while (l1 && l2) {
if (l1.val > l2.val) {
crt.next = l2;
l2 = l2.next;
} else {
crt.next = l1;
l1 = l1.next;
}
crt = crt.next;
}
crt.next = l1 || l2;
return mergedHead.next;
};
mergeTwoLists([1, 2, 4], [1, 3, 4]);