Poison

66. Plus One

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int[] plusOne(int[] digits) {
for (int i = digits.length - 1; i >= 0; i--) {
digits[i] = (digits[i] + 1) % 10;
if (digits[i] != 0) {
return digits;
}
}

int[] res = new int[digits.length + 1];
res[0] = 1;
return res;
}
}
Reference

66. Plus One