Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added solution to Q44 #38

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions leetCode Solutions/Q44_WildcardMatching/Q44_WildcardMatching.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution {
public:
bool isMatch(const string & s, const string & p) {
vector<bool> flags(s.size()+1, 0);
flags[0] = 1;
for (const char & c : p) {
bool prevFlag = flags[0];
flags[0] = flags[0] && c == '*';
for (int j=1; j<=s.size(); ++j) {
bool currentFlag = flags[j];
if (c == '*')
flags[j] = prevFlag || flags[j] || flags[j-1];
else if (c == '?' || c == s[j-1])
flags[j] = prevFlag;
else
flags[j] = false;
prevFlag = currentFlag;
}
}
return flags[s.size()];
}
};