public class Solution {

```
public int[] plusOne(int[] digits) {
int i = digits.length - 1;
while (i >= 0 && digits[i] == 9) i--;
int[] res = new int[digits.length + (i < 0 ? 1 : 0)];
for (int j = 0; j <= i; j++) res[j] = digits[j];
res[i < 0 ? 0 : i]++;
return res;
}
```

}