Skip to content

Commit e005224

Browse files
authored
Merge pull request #58 from bluesword12350/master
010. Regular Expression Matching (JAVA)
2 parents a1d2373 + 1a693c0 commit e005224

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public boolean isMatch(String s, String p) {
3+
boolean[] match = new boolean[s.length() + 1];
4+
match[s.length()] = true;
5+
for (int i = p.length() - 1; i >= 0; i--) {
6+
if (p.charAt(i) == '*') {
7+
for (int j = s.length() - 1; j >= 0; j--) {
8+
match[j] = match[j] || (match[j + 1] && (p.charAt(i - 1) == '.' ||
9+
(p.charAt(i - 1) == s.charAt(j))));
10+
}
11+
i--;
12+
} else {
13+
for (int j = 0; j < s.length(); j++) {
14+
match[j] = match[j + 1] && (p.charAt(i) == '.' || (p.charAt(i) == s.charAt(j)));
15+
}
16+
match[s.length()] = false;
17+
}
18+
}
19+
return match[0];
20+
}
21+
}

0 commit comments

Comments
 (0)