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
483
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交