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 791072c commit e64125aCopy full SHA for e64125a
decode-ways/printjin-gmailcom.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def numDecodings(self, s):
3
+ if not s:
4
+ return 0
5
+ dp = [0] * (len(s) + 1)
6
+ dp[0] = 1
7
+ dp[1] = 1 if s[0] != '0' else 0
8
+ for i in range(2, len(s) + 1):
9
+ if '1' <= s[i - 1] <= '9':
10
+ dp[i] += dp[i - 1]
11
+ if '10' <= s[i - 2:i] <= '26':
12
+ dp[i] += dp[i - 2]
13
+ return dp[len(s)]
0 commit comments