Skip to content

Commit 66882ce

Browse files
authored
Merge pull request #2800 from mdmzfzl/main
Create: 0115-distinct-subsequences.c
2 parents 67f3b4b + 43fa06e commit 66882ce

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

c/0115-distinct-subsequences.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
int numDistinct(char *s, char *t) {
2+
int m = strlen(s);
3+
int n = strlen(t);
4+
5+
uint64_t dp[m + 1][n + 1];
6+
memset(dp, 0, sizeof(dp));
7+
8+
for (int i = 0; i <= m; ++i)
9+
dp[i][0] = 1;
10+
11+
for (int i = 1; i <= m; ++i) {
12+
for (int j = 1; j <= n; ++j) {
13+
if (s[i - 1] == t[j - 1]) {
14+
dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
15+
} else {
16+
dp[i][j] = dp[i - 1][j];
17+
}
18+
}
19+
}
20+
21+
return (int)dp[m][n];
22+
}

0 commit comments

Comments
 (0)