Commit c4416e3d by 李楚霏

work

parent 2ba644c0
/**
* @param {string} s
* @return {number}
*/
var numDecodings = function(s) {
if(!s) return 0;
let len = s.length;
let dp = new Array(len + 1).fill(0);
dp[0]=1;
dp[1] = s[0] === '0'? 0 : 1;
for(let i = 2; i <= len; i++) {
if(s[i - 1] !== '0') {
dp[i] += dp[i-1];
}
if(s[i - 2] === '1' ||(s[i - 2] === '2' && s[i - 1] >= 0 && s[i - 1] <= 6)) {
dp[i] += dp[i-2];
}
}
return dp[len];
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment