My simple C++ solution


  • 0
    Z
    vector<int> plusOne(vector<int> &digits) {
        vector<int> result;
        int carry = 1;
        for(int i = digits.size() - 1; i >= 0; i--){
            int sum = (digits[i] + carry) % 10;
            carry = (digits[i] + carry) / 10;
            result.insert(result.begin(), sum);
        }
        if(carry == 1){
            result.insert(result.begin(), 1);
        }
        return result;
    }

Log in to reply
 

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