It's right in my computer,but it's 'runtime error' in web, why?


  • 0
    L

    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
    int count = 0;
    ListNode* ptr = l1;
    ListNode* ls = ptr;
    if (l1 == nullptr)
    return l2;
    while (l2 != nullptr)
    {
    if (ptr == nullptr)
    {
    int kk = l2->val + count;
    count = kk / 10;
    l2->val = kk % 10;
    ls->next = l2;
    l2 = l2->next;
    ls = ls->next;
    break;
    }
    else
    {
    int kk = ptr->val + l2->val + count;
    count = kk / 10;
    ptr->val = kk % 10;
    ls = ptr;
    ptr = ptr->next;
    l2 = l2->next;
    }

    	 }
    
    	 while (count != 0)
    	 {
    		 if (ls->next == nullptr)
    		 {
    			 ListNode p(count);
    			 ls->next = &p;
    			 count = 0;
    		 }
    		 else
    		 {
    			 int kk = ls->next->val + count;
    			 count = kk / 10;
    			 ls->next->val = kk % 10;
    			 ls = ls->next;
    		 }
    	 }
    	 return l1;
     }

  • 0
    H
    // It's readable on your computer, but it's unreadable on the this page. 
    
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) 
    { 
    	int count = 0; 
    	ListNode* ptr = l1; 
    	ListNode* ls = ptr; 
    	if (l1 == nullptr) 
    		return l2; 
    	while (l2 != nullptr) 
    	{ 
    		if (ptr == nullptr) 
    		{ 
    			int kk = l2->val + count; 
    			count = kk / 10;
    			l2->val = kk % 10; 
    			ls->next = l2; 
    			l2 = l2->next; 
    			ls = ls->next; 
    			break; 
    		} else 
    		{ 
    			int kk = ptr->val + l2->val + count; 
    			count = kk / 10; 
    			ptr->val = kk % 10; 
    			ls = ptr; 
    			ptr = ptr->next; 
    			l2 = l2->next; 
    		}
    	}
    
        while (count != 0)
        {
    		if (ls->next == nullptr)
            {
    			ListNode p(count);
                ls->next = &p;
                count = 0;
            }
            else
            {
    			int kk = ls->next->val + count;
                count = kk / 10;
                ls->next->val = kk % 10;
                ls = ls->next;
            }
    	}
    	return l1;
    }

  • 0
    C

    I confirmed your issue too. I haven't yet figured out why it's happening...


Log in to reply
 

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