Skip to content

Commit

Permalink
Update 0115.不同的子序列.md
Browse files Browse the repository at this point in the history
  • Loading branch information
z80160280 authored Jun 9, 2021
1 parent a4b7399 commit 95fa60c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion problems/0115.不同的子序列.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,22 @@ Java:
Python:
```python
class Solution:
def numDistinct(self, s: str, t: str) -> int:
dp = [[0] * (len(t)+1) for _ in range(len(s)+1)]
for i in range(len(s)):
dp[i][0] = 1
for j in range(1, len(t)):
dp[0][j] = 0
for i in range(1, len(s)+1):
for j in range(1, len(t)+1):
if s[i-1] == t[j-1]:
dp[i][j] = dp[i-1][j-1] + dp[i-1][j]
else:
dp[i][j] = dp[i-1][j]
return dp[-1][-1]
```

Go:

Expand Down

0 comments on commit 95fa60c

Please sign in to comment.