class Solution {
public:
int numDistinct(string S, string T) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int res = 0;
match(S, T, 0, 0, res);
return res;
}
void match(string& s, string& t, int idxS, int idxT, int& res)
{
if (t.size() == 0) return;
if (idxT >= t.size() || idxS >= s.size()) return;
if (t[idxT] == s[idxS])
{
if (idxT == t.size() - 1)
{
++res;
}
else
match(s, t, idxS + 1, idxT + 1, res);
}
match(s, t, idxS + 1, idxT, res);
}
};
[Leetcode] Distinct Subsequences *
最新推荐文章于 2019-05-06 23:39:39 发布