We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Learn more about funding links in repositories.
Report abuse
1 parent 4604d21 commit 8f3b0bdCopy full SHA for 8f3b0bd
solution/0100-0199/0115.Distinct Subsequences/Solution.cpp
@@ -0,0 +1,14 @@
1
+class Solution {
2
+public:
3
+ int numDistinct(string s, string t) {
4
+ int m = s.size(), n = t.size();
5
+ vector<vector<long>> dp(n + 1, vector<long>(m + 1));
6
+ for (int j = 0; j <= m; ++j) dp[0][j] = 1;
7
+ for (int i = 1; i <= n; ++i) {
8
+ for (int j = 1; j <= m; ++j) {
9
+ dp[i][j] = dp[i][j - 1] + (t[i - 1] == s[j - 1] ? dp[i - 1][j - 1] : 0);
10
+ }
11
12
+ return dp[n][m];
13
14
+};
0 commit comments