Created
December 21, 2019 13:31
-
-
Save shubham1710/498876c6df2c67e34748d320c07e9200 to your computer and use it in GitHub Desktop.
Ddsszz
This file contains hidden or 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
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