Solution C++ . . . . . .


#1
ListNode* Solution::addTwoNumbers(ListNode* A, ListNode* B) {
    ListNode* ptr = new ListNode(0);
    ListNode* start = ptr;
    int c=0;
    
    while(A || B)
    {
        int a=0,b=0;
        if(A)
            a=A->val;
        if(B)
            b=B->val;
        int x = a+b+c;
        c = x/10;
        x = x%10;
        ListNode* temp = new ListNode(x);
        ptr->next = temp;
        ptr = temp;
        
        if(A)
            A = A->next;
        if(B)
            B = B->next;
    }
    
    if(c)
    {
        ListNode* temp = new ListNode(c);
        ptr->next = temp;
        ptr = temp;
    }
    
    return start->next;
}