Title: #66 - Plus One - LeetCode JavaScript Solutions
Open Graph Title: #66 - Plus One - LeetCode JavaScript Solutions
X Title: #66 - Plus One - LeetCode JavaScript Solutions
Description: Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most sig...
Open Graph Description: Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most sig...
X Description: Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most sig...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/plus-one
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/plus-one","name":"#66 - Plus One - LeetCode JavaScript Solutions","description":"Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most sig...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[]} digits\n * @return {number[]}\n */\nvar plusOne = function(digits) {\n let i = digits.length - 1;\n digits[i] += 1;\n while (digits[i] > 9) {\n digits[i--] = 0;\n if (digits[i]) {\n digits[i] += 1;\n } else {\n digits.unshift(1);\n }\n }\n return digits;\n};\n\n// alternative one-liner that breaks the rules:\n/**\n * @param {number[]} digits\n * @return {number[]}\n */\nvar plusOne = function(digits) {\n return String(BigInt(digits.join('')) + BigInt(1)).split('');\n};","keywords":"LeetCode 66, #66 - Plus One, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/plus-one |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/plus-one/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0066-plus-one.js |
| Array | https://leetcodejavascript.com/tags/array |
| Math | https://leetcodejavascript.com/tags/math |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow