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 0eb2084 commit ab0ada0Copy full SHA for ab0ada0
distinct_subsequences/solution2.py
@@ -0,0 +1,14 @@
1
+class Solution:
2
+ # @return an integer
3
+ def numDistinct(self, S, T):
4
+ m = len(S)
5
+ n = len(T)
6
+ dp = [[0 for j in range(m + 1)] for i in range(n + 1)]
7
+ for j in range(m + 1):
8
+ dp[0][j] = 1
9
+ for i in range(1, n + 1):
10
+ for j in range(1, m + 1):
11
+ dp[i][j] = dp[i][j - 1]
12
+ if T[i - 1] == S[j - 1]:
13
+ dp[i][j] += dp[i - 1][j - 1]
14
+ return dp[n][m]
0 commit comments