Skip to content

Commit 4800714

Browse files
Merge pull request #368 from z80160280/z80160280-patch-13
Update 0115.不同的子序列.md
2 parents f1b2eda + 95fa60c commit 4800714

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

problems/0115.不同的子序列.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,22 @@ Java:
148148
149149
150150
Python:
151-
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+
```
152167

153168
Go:
154169

0 commit comments

Comments
 (0)