public static int[] plusOne(int[] digits) {
int l = digits.length;
int[] ret = new int[l+1];
int remain = (digits[l-1] + 1) / 10;
digits[l-1] = (digits[l-1] + 1) % 10;
if (remain == 0)
return digits; // 最后一位<9
for (int i = l-2; i >= 0; i--)
{
int tmp = digits[i] + remain;
digits[i] = tmp % 10;
remain = tmp / 10;
if (remain == 0)
return digits; // 中间有位<9
}
ret[0] = 1;
// for (int i = 1; i < l+1; i++)
// ret[i] = digits[i-1];
return ret; // 需要增加一位
}
08-05
219
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-02
93
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-03
1068
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
02-27