Skip to content

Instantly share code, notes, and snippets.

@RP-3
Created July 6, 2020 08:23
Show Gist options
  • Save RP-3/8f3516e7ff15c3726d1ac4b5d0a322b4 to your computer and use it in GitHub Desktop.
Save RP-3/8f3516e7ff15c3726d1ac4b5d0a322b4 to your computer and use it in GitHub Desktop.
var plusOne = function(digits) {
let [carry, i] = [1, result.length-1];
while(carry && i >=0){
const n = result[i] + carry;
carry = (n === 10) ? 1 : 0;
digits[i--] = n % 10;
}
if(carry) digits.unshift(1);
return digits;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment