Skip to content

Commit 8f3b0bd

Browse files
committedDec 24, 2020
feat:add Solution.cpp for 0115. Distinct Subsequences
1 parent 4604d21 commit 8f3b0bd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
Please sign in to comment.