Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
class Solution {
public int[] plusOne(int[] digits) {//将一个表示为数组形式的数组进行加一
int l=digits.length;//l=1
int ans[]=new int[l+1];
for(int i=l;i>0;i--){
ans[i]=digits[i-1];
}
ans[l]++;
for(int i=l;i>0;i--){
if(ans[i]==10){
ans[i]=0;
ans[i-1]++;
}
}
if(ans[0]==0){
for(int i=l;i>0;i--)
digits[i-1]=ans[i];
return digits;
}
return ans;
}
}