void plusone(vector<int> &digits)
{
int n = digits.size();
for (int i = n  1; i >= 0; i)
{
if (digits[i] == 9)
{
digits[i] = 0;
}
else
{
digits[i]++;
return;
}
}
digits[0] =1;
digits.push_back(0);
}
Is it a simple code(C++)?

This is a Java version using the same idea.
public class Solution { public int[] plusOne(int[] digits) { int length = digits.length  1; while (length >= 0) { if (digits[length] == 9) { digits[length] = 0; } else { digits[length]++; return digits; } } int[] res = new int[digits.length + 1]; res[0] = 1; return res; } }

Not as smart as zezedi, but does the work:
public int[] plusOne(int[] digits) { int carry = 1; int[] res = new int[digits.length+1]; for(int i=digits.length1; i>=0; i) { if(digits[i] == 9 && carry == 1) { res[i] = 0; carry = 1; } else { res[i] = digits[i] + carry; carry = 0; } } if(carry==0) res = Arrays.copyOfRange(res, 0, digits.length); else res[0] = carry; return res; }

@Yan_Sylvia_Liu The loop simply turns all trailing nines into zeros and if it comes across a nonnine, it increases that and returns. I don't understand your other two questions, sorry.

you are very smart, I translate is it to my c code
int* plusOne(int* digits, int digitsSize, int* returnSize) { if(digitsSize < 1) { return NULL; } int breakflag = 0; int * result = (int*)malloc(sizeof(int)*(digitsSize+1)); for(int i = digitsSize  1; i >= 0; i ) { if(digits[i] == 9 && !breakflag) { result[i+1] = 0; }else if(!breakflag) { result[i+1] = digits[i]+1; breakflag = 1; }else { result[i+1] =digits[i]; } } if(!breakflag) { result[0] = 1; *returnSize = digitsSize+1; return result; }else{ *returnSize = digitsSize; return result+1; }
}