Skip to content

Instantly share code, notes, and snippets.

@Onaiplee
Created July 15, 2014 18:14
Show Gist options
  • Save Onaiplee/526321812518835bffc3 to your computer and use it in GitHub Desktop.
Save Onaiplee/526321812518835bffc3 to your computer and use it in GitHub Desktop.
class Solution {
public:
int numDistinct(string S, string T) {
return numDistinct(S, T, 0, 0);
}
int numDistinct(string S, string T, int s, int t) {
if (t == T.size()) {
return 1;
}
if (s == S.size()) {
return 0;
}
if (S[s] == T[t]) {
return numDistinct(S, T, s + 1, t + 1) + numDistinct(S, T, s + 1, t);
} else {
return numDistinct(S, T, s + 1, t);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment