1Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
题意:给一个数的数组形式(例如78 digits[0]=7,digits[1]=8),每一位加1,返回一个数组形式。注意99 digits[0]=9,digits[1]=9,返回应该为nums[0]=1,nums[1]=0,nums[2]=0,100
code:
public int[] plusOne(int[] digits) {
for(int i = digits.length-1; i>=0; i--){
if(digits[i]<9){
digits[i]++;
return digits;
}
digits[i] =0;
}
int[] nums = new int[digits.length+1];
nums[0]=1;
return nums;
}