Simple C++ source code


  • -3
    N
        std::reverse(digits.begin(), digits.end());
        int carry = 1;
        
        for(vector<int>::iterator iter = digits.begin(); iter != digits.end(); iter++)
        {
            if(*iter != 9)
            {
                *iter += carry;
                carry = 0;
                break;
            }
            else if(carry == 1)
                *iter = 0;
        }
        if(carry == 1)
            digits.push_back(1);
        
        std::reverse(digits.begin(), digits.end());
        return digits;

Log in to reply
 

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