C语言 | Leetcode C语言题解之第115题不同的子序列
题目:
题解:
int numDistinct(char* s, char* t) {
int m = strlen(s), n = strlen(t);
if (m < n) {
return 0;
}
unsigned long long dp[m + 1][n + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= m; i++) {
dp[i][n] = 1;
}
for (int i = m - 1; i >= 0; i--) {
char sChar = s[i];
for (int j = n - 1; j >= 0; j--) {
char tChar = t[j];
if (sChar == tChar) {
dp[i][j] = dp[i + 1][j + 1] + dp[i + 1][j];
} else {
dp[i][j] = dp[i + 1][j];
}
}
}
return dp[0][0];
}
原文地址:https://blog.csdn.net/m0_59237910/article/details/139252158
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!