Skip to content

Commit 1c50ffb

Browse files
authoredOct 19, 2018
Add files via upload
1 parent 668652d commit 1c50ffb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎Decode Ways/Decode_Ways.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 动态规划
2+
# 40ms 100%
3+
class Solution:
4+
def numDecodings(self, s):
5+
if not s:
6+
return 0
7+
dp = [0 for _ in range(len(s)+1)]
8+
dp[0] = 1
9+
for i in range(1, len(s)+1):
10+
if s[i-1] != "0":
11+
dp[i] += dp[i-1]
12+
if i != 1 and '10' <= s[i-2:i] <= "26":
13+
dp[i] += dp[i-2]
14+
return dp[-1]

0 commit comments

Comments
 (0)
Please sign in to comment.