Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool isMatch(string s, string p) {
- for( int i=0 ; i<p.size() ; i++)
- {
- if(p[i] == '*')
- {
- if(p[i-1] != '.')
- p[i-1] -= 32;
- else p[i-1]--;
- p.erase(i, 1);
- i--;
- }
- }
- cout << p << endl;
- return check(p, s, 0, 0);
- }
- bool check(string s, string p, int i, int j) {
- if(p.size() == j) return true;
- if(s.size() == i) return false;
- bool result = false;
- if(s[i] >= 97)
- {
- if(s[i] == p[j]) result = result || check(s, p, i+1, j+1);
- else return false;
- }
- else if(s[i] == '.')
- {
- result = result || check(s, p, i+1, j+1);
- }
- else if(s[i] == '.' - 1)
- {
- result = result || check(s, p, i, j+1);
- result = result || check(s, p, i+1, j);
- }
- else
- {
- if(s[i]+32 == p[j]) result = result || check(s, p, i, j+1);
- result = result || check(s, p, i+1, j);
- }
- return result;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement