Skip to content

Commit fe203c8

Browse files
authored
Update 91.decode-ways.md
1 parent b65f296 commit fe203c8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

problems/91.decode-ways.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ s 只包含数字,并且可以包含前导零。
8383

8484
## 代码
8585

86-
代码支持: JS,CPP
86+
代码支持: JS, Python3,CPP
8787

8888
JS Code:
8989

@@ -116,6 +116,27 @@ var numDecodings = function (s) {
116116
};
117117
```
118118

119+
Python3 Code:
120+
121+
```py
122+
class Solution:
123+
def numDecodings(self, s: str) -> int:
124+
@lru_cache(None)
125+
def dp(start):
126+
if start == len(s):
127+
return 1
128+
if start > len(s):
129+
return 0
130+
if s[start] != "0":
131+
if s[start : start + 2] <= "26":
132+
print(s[start : start + 2])
133+
return dp(start + 1) + dp(start + 2)
134+
return dp(start + 1)
135+
return 0
136+
137+
return dp(0)
138+
```
139+
119140
**复杂度分析**
120141

121142
- 时间复杂度:$O(N)$

0 commit comments

Comments
 (0)