/**
* @param {string} s
* @return {number}
*/
var numDecodings = function(s) {
if (s[0] == 0) return 0;
if (s.length === 1) return 1;
const arr = new Array(s.length).fill(0);
arr[0] = 1;
for (let i = 1; i < arr.length; i++) {
const curr = s[i];
const prev = s[i - 1];
// 1
if (curr != 0) {
arr[i] += arr[i - 1];
}
// 2
if (prev == 1 || (prev == 2 && curr <= '6')) {
arr[i] = i == 1 ? arr[i] + 1 : arr[i] + arr[i - 2];
}
}
return arr[s.length - 1];
};