```
public class Solution {
public int[] plusOne(int[] digits) {
int extra = 0;
int index = digits.length - 1;
int[] result = new int[digits.length];
while (index >= 0 && digits[index] == 9) {
digits[index] = 0;
index--;
}
if (index == -1) {
result = new int[digits.length+1];
result[0] = 1;
}else {
digits[index] += 1;
return digits;
}
return result;
}
```

}