Skip to content

Commit d65a67f

Browse files
committed
RegularExpressionMatching10
1 parent 54bd355 commit d65a67f

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

src/RegularExpressionMatching10.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public boolean isMatch5(String s, String p) {
139139
dp[i][j] = dp[i-1][j-1];
140140
break;
141141
case '*':
142-
dp[i][j] = dp[i][j-2] || isMatch(dp, s, i, p, j);
142+
dp[i][j] = dp[i][j-2] || ((p.charAt(j-2) == '.' || p.charAt(j-2) == s.charAt(i-1)) && dp[i-1][j]);
143143
break;
144144
default:
145145
dp[i][j] = s.charAt(i-1) == p.charAt(j-1) && dp[i-1][j-1];
@@ -149,14 +149,4 @@ public boolean isMatch5(String s, String p) {
149149
return dp[s.length()][p.length()];
150150
}
151151

152-
private boolean isMatch(boolean[][] dp, String s, int i, String p, int j) {
153-
char c = p.charAt(j-2);
154-
while (i >= 1 && (c == '.' || s.charAt(i-1) == c)) {
155-
if (dp[i][j-1]) return true;
156-
else i--;
157-
}
158-
return false;
159-
}
160-
161-
162152
}

0 commit comments

Comments
 (0)