Skip to content

Commit 77d109d

Browse files
committed
2
1 parent 49499ef commit 77d109d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
public:
3+
int numDistinct(string S, string T) {
4+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
7+
int M = S.size();
8+
int N = T.size();
9+
10+
if (M == 0 && N == 0)
11+
return 1;
12+
else if (M < N)
13+
return 0;
14+
15+
int F[N+1];
16+
memset(F, 0, sizeof(int)*(N+1));
17+
F[0] = 1;
18+
for (int i = 1; i <= M; i++) {
19+
for (int j = N; j >= 1; j--) {
20+
if (S[i-1] == T[j-1])
21+
F[j] = F[j-1] + F[j];
22+
}
23+
}
24+
return F[N];
25+
}
26+
};

0 commit comments

Comments
 (0)