• + 0 comments

    function mergeLists(head1, head2) { let newNode = new SinglyLinkedListNode(); let tail = newNode;

    while(head1 !==null && head2 !== null){
        if(head1.data < head2.data){
            tail.next = head1;
            head1= head1.next;
        }else if(head2.data <= head1.data){
            tail.next = head2;
            head2 = head2.next;
        }
        tail = tail.next;
    
    
        if(head1 !==null){
            tail.next = head1;
        }else if(head2 !== null){
            tail.next = head2;
        }
    }
        return newNode.next;
    

    }