1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
var plusOne = function (digits) { const len = digits.length; let count = len - 1;
while (count >= 0) { if(digits[count] < 9) { digits[count] ++;
return digits; } digits[count] = 0; count --; }
return [1, ...digits]; };
|