题目
题目链接
题解
class Solution {
public int[] plusOne(int[] digits) {
for (int i = digits.length - 1; i >= 0; i--) {
if (++digits[i] > 9) {
digits[i] = 0;
} else {
break;
}
}
if (digits[0] == 0) {
int[] newArray = new int[digits.length + 1];
System.arraycopy(digits, 0, newArray, 1, digits.length);
newArray[0] = 1;
return newArray;
}
return digits;
}
}