Type:easy
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int n = digits.size();
int i;
if(digits[n-1] != 9){
digits[n-1] += 1;
return digits;
}else{
for(i=n-1; i>=0; --i){
if(digits[i] == 9) digits[i] = 0;
else break;
}
if(i != -1){
digits[i] += 1;
return digits;
}else{
vector<int> ret(n+1, 0);
for(int j=1; j<n+1; j++) ret[j] = digits[j-1];
ret[0] = 1;
return ret;
}
}
return digits;
}
};