What is meaning of runtime error: Last execute: {},{}


  • 1
    Z
    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     ListNode *next;
     *     ListNode(int x) : val(x), next(NULL) {}
     * };
     */
    class Solution {
    public:
        ListNode *mergeTwoLists(ListNode *l1, ListNode *l2) {
        ListNode * head;
        ListNode * cursor;
    	
    	ListNode *l1Cursor = l1;
    	ListNode *l2Cursor = l2;
        
        //cout<<l1Cursor->val<<endl;
        //cout<<l2Cursor->val<<endl;
    	if(l1Cursor->val > l2Cursor->val)
        {
        	head = l1Cursor;
        	
        	cursor = head;
        	l1Cursor = l1Cursor->next;
        	
        }
    	else
    	{
    		head = l2Cursor;
    		cursor= head;
    		l2Cursor = l2Cursor->next;
    		
    	}
    	
    	//cout<<head->val<<endl;
    	while(l1Cursor != NULL && l2Cursor != NULL){
    		//cout<<"test"<<endl;
    		//cout<<cursor->val<<endl;
    		if(l1Cursor->val > l2Cursor->val)
    		{
    		
    			cursor->next = l1Cursor;
    			cursor = cursor->next;
    			
    			l1Cursor = l1Cursor->next;
    		}
    		else
    		{
    		
    			cursor->next = l2Cursor;
    			cursor = cursor->next;
    			
    			l2Cursor = l2Cursor->next;
    			
    		}
    		
    		
    	}
    	
    	if(l1Cursor != NULL){
    	
            cursor->next = l1Cursor;
    		
    	}
    	if(l2Cursor != NULL){
    
            cursor->next = l2Cursor;
    	    
       }	 
    	
    	return head;	
       }
    };

  • 0
    T

    Guess it means you should take care if either inputs l1 or l2 is a null pointer...


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.