I'm aware that this initial solution is very expensive, I just wanted to get the green before I tighten it up and start experimenting. When my solution failed a test on Leetcode, I put their parameter into my unit test and it passed. Any ideas why it works on my machine and not on their server?
function plusOne(digits) {
let stringOfDigits = digits.reduce((str, int) => str + int, "")
return Array.from(String(parseInt(stringOfDigits) + 1), Number)
}
Here's what I'm getting from Leetcode:
Input:
[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,3]
Output:
[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,0,0,0]
Expected:
[6,1,4,5,3,9,0,1,9,5,1,8,6,7,0,5,5,4,4]