Skip to content

Instantly share code, notes, and snippets.

@iamandrewluca
Created February 1, 2024 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamandrewluca/cb339b31d666b9d74537a8603792c872 to your computer and use it in GitHub Desktop.
Save iamandrewluca/cb339b31d666b9d74537a8603792c872 to your computer and use it in GitHub Desktop.
function plusOne(digits) {
let index = digits.length - 1
while (true) {
digits[index] += 1;
if (digits[index] > 9 && index === 0) {
digits[index] = 0
digits.unshift(1);
break;
}
if (digits[index] > 9) {
digits[index] = 0
index--;
} else {
break;
}
}
return digits
}
plusOne([1,1,9])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment