I've added 3 hard challenges to codr's ranked mode. Two are related to important algorithms, below is the third related to cryptography. Visit codr for more https://nevolin.be/codr/
Can you solve it?
function numDecodings(s) {
if (s == null || s.length == 0) {
return 0;
}
const dp = Array(s.length + 1).fill(0);
dp[0] = 1;
dp[1] = s[0] !== "0" ? 1 : 0;
for (let i = 2; i < s.length + 1; i++) {
const one = +s.slice(i - 1, i);
const two = +s.slice(i - 2, i);
if (two >= 10 && two <= 26) {
dp[i] = dp[i - 2];
}
if (one >= 1 && one <= 9) {
dp[i] += dp[i - 1];
}
}
return dp[dp.length - 1];
}
let A = numDecodings('5646');
// A = ?
Top comments (1)
A=1