Created
March 10, 2020 15:06
-
-
Save ms314006/fd7a78db48acc56688741ae369b7c330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var plusOne = function(digits) { | |
for(let i = digits.length - 1; i >= 0; i--) { | |
let lastDigit = digits[i]; | |
if (lastDigit < 9) { | |
digits[i] += 1; | |
return digits; | |
} | |
digits[i] = 0; | |
} | |
return [1, ...digits] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment