1
class Solution {
2
public:
3
bool isMatch(string s, string p) {
4
return helper(s, p, 0, 0);
5
}
6

7
bool helper(string s, string p, int i, int j) {
8
if (j == p.length()) return i == s.length();
9
bool first_match = (i < s.length() && (s[i] == p[j] || p[j] == '.'));
10

11
if (j + 1 < p.length() && p[j + 1] == '*') {
12
return (helper(s, p, i, j + 2) || (first_match && helper(s, p, i + 1, j)));
13
} else {
14
return (first_match && helper(s, p, i + 1, j + 1));
15
}
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0