-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path44.cpp
More file actions
38 lines (34 loc) · 1.13 KB
/
44.cpp
File metadata and controls
38 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 44. Wildcard Matching
// Link : https://leetcode.com/problems/wildcard-matching/
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
bool isMatch(string s, string p) {
int patternPointer = 0;
int stringPointer = 0;
// looop over string and check it in pattern, if pattern is not wildcard then increase the patternPointer.
for (; stringPointer < s.size();) {
if (patternPointer >= p.size()) {
return false;
}
if (p.at(patternPointer) == '?' || p.at(patternPointer) == s.at(stringPointer)) {
patternPointer++;
} else if (p.at(patternPointer) == '*') {
if (patternPointer < p.size() - 1)
return isMatch(s, p.erase(patternPointer));
return true;
}
return false;
}
if (patternPointer < p.size() && p.at(patternPointer) != '*' && p.at(patternPointer) != '?')
return false;
return true;
}
};
int main() {
Solution ob;
cout << ob.isMatch("adceb", "*a*b");
}