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 b65f296 commit fe203c8Copy full SHA for fe203c8
problems/91.decode-ways.md
@@ -83,7 +83,7 @@ s 只包含数字,并且可以包含前导零。
83
84
## 代码
85
86
-代码支持: JS,CPP
+代码支持: JS, Python3,CPP
87
88
JS Code:
89
@@ -116,6 +116,27 @@ var numDecodings = function (s) {
116
};
117
```
118
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
136
137
+ return dp(0)
138
+```
139
140
**复杂度分析**
141
142
- 时间复杂度:$O(N)$
0 commit comments