class Solution {
public int[] plusOne(int[] digits) {
List<Integer> list = new ArrayList<>();
int temp = 1;
for (int i = digits.length-1; i >= 0; i--){
list.add((digits[i]+temp)%10);
temp = (digits[i]+temp)/10;
}
if(temp != 0){
list.add(temp);
}
int[] result = new int[list.size()];
for (int i = 0; i < list.size(); i++){
result[list.size()-1-i] = list.get(i);
}
return result;
}
}
网友评论