Skip to content

Instantly share code, notes, and snippets.

@shubham1710
Created December 21, 2019 13:31
Show Gist options
  • Save shubham1710/498876c6df2c67e34748d320c07e9200 to your computer and use it in GitHub Desktop.
Save shubham1710/498876c6df2c67e34748d320c07e9200 to your computer and use it in GitHub Desktop.
Ddsszz
bool isAsterisk(char c){
return c == '*';
}
bool isQuestion(char c){
return c == '?';
}
bool isMatchSymbol(char s, char m){
return isQuestion(m) || s == m;
}
int Solution::isMatch(const string source, const string mask) {
int S = source.length();
int M = mask.length();
vector<bool> dp(S + 1, false);
dp[S] = true;
for(int m = M - 1; m >= 0; m--){
vector<bool> newDp(S + 1, false);
if(isAsterisk(mask[m]))
newDp[S] = dp[S];
for(int s = S - 1; s >= 0; s--){
if(isAsterisk(mask[m])){
newDp[s] = dp[s] || dp[s + 1] || newDp[s + 1];
} else {
newDp[s] = dp[s + 1] && isMatchSymbol(source[s], mask[m]);
}
}
dp = newDp;
}
return dp[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment