class Solution {
public:
int numDistinct(string S, string T) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int s_len = S.size();
int t_len = T.size();
vector<int> rec (t_len + 1);
rec[0] = 1;
for (int i = 0; i < s_len; i++) {
for (int j = t_len - 1; j >= 0; j--) {
rec[j + 1] += (S[i] == T[j]) * rec[j];
}
}
return rec[t_len];
}
};
LeetCode Distinct Subsequences
最新推荐文章于 2017-07-04 10:43:23 发布