leetcode上的一道题,做的很爽。
public boolean isMatch(String s, String p) {
int i = 0, j = 0, x = 0, y = -1, l = p.length();
while (i < s.length()) {
if (j < l && (p.charAt(j) == '?' || p.charAt(j) == s.charAt(i))) {
i++;
j++;
} else if (j < l && p.charAt(j) == '*') {
x = i;
y = j++;
} else if (y >= 0) {
i = ++x;
j = y + 1;
} else {
return false;
}
}
while (j < l && p.charAt(j) == '*') {
j++;
}
return j == l;
}