Given a number represented as an array of digits, plus one to the number.
数字加1
public class Solution {
public int[] plusOne(int[] digits) {
int flag = 1;
for(int i=digits.length-1;i>=0;i--){
int num = digits[i]+flag;
flag=num/10;
digits[i]=num%10;
}
if(flag==0)
return digits;
int[] res = new int[digits.length+1];
res[0]=1;
for(int i=0;i<digits.length;i++){
res[i+1]=digits[i];
}
return res;
}
}