Created
July 15, 2014 18:14
-
-
Save Onaiplee/526321812518835bffc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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