Runtime error -- Don't know what to do

ListNode* Solution::mergeTwoLists(ListNode* A, ListNode* B) {

    ListNode *first=A,*second=B,*nn=NULL,*head=NULL;

    if(first->val<=second->val)
    {
        nn=first;
        head=nn;
        nn->next=NULL;
        first=first->next;

    }
    else{
        nn=second;
        head=nn;
        nn->next=NULL;
        second=second->next;
    }

    while(first|| second)
    {
        if(first->val<=second->val)
        {
            nn->next=first;
            nn=nn->next;
            nn->next=NULL;
            first=first->next;
        }
        else{
            nn->next=second;
            nn=nn->next;
            nn->next=NULL;
            second=second->next;
        }
    }

    while(first)
    {
        nn->next=first;
        nn=nn->next;
        nn->next=NULL;
        first=first->next;
    }

    while(second)
    {
        nn->next=second;
        nn=nn->next;
        nn->next=NULL;
        second=second->next;
    }
    
    return head;
}

Click here to start solving coding interview questions