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.
2 parents f1b2eda + 95fa60c commit 4800714Copy full SHA for 4800714
problems/0115.不同的子序列.md
@@ -148,7 +148,22 @@ Java:
148
149
150
Python:
151
-
+```python
152
+class Solution:
153
+ def numDistinct(self, s: str, t: str) -> int:
154
+ dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]
155
+ for i in range(len(s)):
156
+ dp[i][0] = 1
157
+ for j in range(1, len(t)):
158
+ dp[0][j] = 0
159
+ for i in range(1, len(s)+1):
160
+ for j in range(1, len(t)+1):
161
+ if s[i-1] == t[j-1]:
162
+ dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
163
+ else:
164
+ dp[i][j] = dp[i-1][j]
165
+ return dp[-1][-1]
166
+```
167
168
Go:
169
0 commit comments