[Written explanation will be added soon]
AFFILIATE LINKS
Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard
Here is the full implementation.
/**
* @param {number[]} digits
* @return {number[]}
*/
let plusOne = function(digits) {
for (let i = digits.length - 1; i >= 0; i--) {
if (digits[i] !== 9) {
digits[i]++;
return digits;
} else {
digits[i] = 0;
}
}
digits.unshift(1);
return digits;
};