Simple C++ solution


  • 0

    Here is a simple C++ solution:

    class Solution {
    public:
        vector<int> plusOne(vector<int>& digits) {
            vector<int>::iterator it;
            for (it = digits.end() - 1;
                it >= digits.begin() && *it == 9;
                *(it--) = 0) ;
            if (it < digits.begin()) digits.insert(digits.begin(), 1);
            else (*it)++;
            return digits;
        }
    };
    

Log in to reply
 

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