LeetCode: Plus One Solution
1/**2 * @param {number[]} digits3 * @return {number[]}4 */5var plusOne = function (digits) {6 let mem = 07 digits = digits.reverse().map((digit, i) => {8 digit += mem + (i === 0 ? 1 : 0)9 if (digit > 9) {10 mem = 111 digit = 012 } else {13 mem = 014 }15 return digit16 })17 if (mem === 1) {18 digits.push(1)19 }20 return digits.reverse()21}
Comments
Loading comments...
Tags
leetcode
array
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.