class Solution:
def numDecodings(self, s: str) -> int:
n = len(s)
dp = [1] * (n + 1)
if s[0] == '0':
return 0
for i in range(2, n + 1):
if s[i - 1] != '0':
dp[i] = dp[i - 1]
else:
dp[i] = 0
if s[i - 2] != '0' and s[i - 2:i] <= "26":
dp[i] += dp[i - 2]
return dp[-1]
11-12
489
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)