We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8771f03 commit cf50f90Copy full SHA for cf50f90
decode-ways/mangodm-web.py
@@ -0,0 +1,16 @@
1
+class Solution:
2
+ def numDecodings(self, s: str) -> int:
3
+ if s[0] == "0":
4
+ return 0
5
+
6
+ n = len(s)
7
+ dp = [0] * (n + 1)
8
+ dp[0], dp[1] = 1, 1
9
10
+ for i in range(2, n + 1):
11
+ if s[i - 1] != "0":
12
+ dp[i] += dp[i - 1]
13
+ if "10" <= s[i - 2 : i] <= "26":
14
+ dp[i] += dp[i - 2]
15
16
+ return dp[n]
0 commit comments