3.23 讲道理,我这个真的不是什么优秀的代码。
但是也奇迹般的A 了,
public class Solution {
/**
* @param digits a number represented as an array of digits
* @return the result
*/
public int[] plusOne(int[] digits) {
int i = digits.length-1;
do{
if(digits[i] < 9){// Write your code here
digits[i] = digits[i] + 1;
break;//return digits;
}
else{
digits[i] = 0;
i--;
}
if(i == 0 && digits[0] == 9){
int[] temp = new int[digits.length+1];
temp[0] = 1;
digits = temp;
}
else if(i == 0 && digits[0] != 9){
digits[0]++;
}
if(i == -1){
int[] temp = {1,0};
digits = temp;
}
//return temp;
}while(i > 0);
return digits;
}
}