Given 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.
Java:
1.http://blog.youkuaiyun.com/linhuanmars/article/details/22365957
public int[] plusOne(int[] digits) {
if(digits == null || digits.length==0)
return digits;
int carry = 1;
for(int i=digits.length-1;i>=0;i--)
{
int digit = (digits[i]+carry)%10;//余数当做此位的新值
carry = (digits[i]+carry)/10; //新的进位
digits[i] = digit;
if(carry==0)
return digits;
}
int [] res = new int[digits.length+1];
res[0] = 1;
return res;
}