public class Solution {
public boolean isCarry(int num) {
return (num/10 == 1) ? true : false;
}
public int[] plusOne(int[] digits) {
int i = digits.length-1;
while (i>-1) {
if (!isCarry(++digits[i])) return digits;
else digits[i--] = 0;
}
// if previous codes don't return, it must be the case e.g. 9999+1
// therefore, create an array and set the value as 10000
// deafault value is 0, just need to set the first value as 1
int[] new_dig = new int[digits.length+1];
new_dig[0] = 1;
return new_dig;
}
}
Leetcode 66. Plus One
最新推荐文章于 2020-11-28 22:12:38 发布