My c++ solution


  • 0
    X

    class Solution {
    public:
    vector<int> plusOne(vector<int>& digits) {
    int i=digits.size();
    digits[i-1]++;
    for(int j=i-1;j>0;j--)
    {
    if(digits[j]==10)
    {
    digits[j]=0;
    digits[j-1]++;
    }
    }
    if (digits[0]==10)
    {
    digits[0]=0;
    digits.insert(digits.begin(),1);
    }
    return digits;
    }
    };


Log in to reply
 

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