Code works during custom test case, but fails with Runtime Error on Submit Solution.


  • 0
    R

    Here's my code, which works for input
    [0]
    [1]

    However, on submitting, I get this error:

    RuntimeError: Last executed input:
    [0]
    [1]

    I'm quite new to LeetCode. Is there a way to access a console and see the runtime error? Appreciate your help!

    struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
        int carry = 0;
        bool rootNode = true;
        struct ListNode *result, *prev, *root = NULL;
        while((l1 != NULL) || (l2 != NULL) || (carry!=0)) {
            int raw_sum = ((l1)? l1->val:0) + ((l2)? l2->val:0) + carry;
            int sum = raw_sum % 10;
            carry = (raw_sum==sum)? 0:1;
            result = malloc(sizeof(struct ListNode));
            if(rootNode) {
                root = result;
                rootNode = false;
            }
            if(prev)        
                prev->next = result;
            prev = result;
            result->val = sum;
            if(l1) 
                l1 = l1->next;
            if(l2) 
                l2 = l2->next;
        }
         return root;
    }
    

Log in to reply
 

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