We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents a1d2373 + 1a693c0 commit e005224Copy full SHA for e005224
solution/010. Regular Expression Matching/Solution.java
@@ -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