Skip to content

Commit 2523f23

Browse files
committed
Runtime: 5 ms (Top 57.68%) | Memory: 42.9 MB (Top 39.28%)
1 parent a11ce93 commit 2523f23

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
// Runtime: 5 ms (Top 57.68%) | Memory: 42.9 MB (Top 39.28%)
12
class Solution {
23
public boolean isMatch(String s, String p) {
34
if (p == null || p.length() == 0) return (s == null || s.length() == 0);
4-
5+
56
boolean dp[][] = new boolean[s.length()+1][p.length()+1];
67
dp[0][0] = true;
78
for (int j=2; j<=p.length(); j++) {
8-
dp[0][j] = p.charAt(j-1) == '*' && dp[0][j-2];
9+
dp[0][j] = p.charAt(j-1) == '*' && dp[0][j-2];
910
}
10-
11+
1112
for (int j=1; j<=p.length(); j++) {
1213
for (int i=1; i<=s.length(); i++) {
13-
if (p.charAt(j-1) == s.charAt(i-1) || p.charAt(j-1) == '.')
14-
dp[i][j] = dp[i-1][j-1];
14+
if (p.charAt(j-1) == s.charAt(i-1) || p.charAt(j-1) == '.')
15+
dp[i][j] = dp[i-1][j-1];
1516
else if(p.charAt(j-1) == '*')
16-
dp[i][j] = dp[i][j-2] || ((s.charAt(i-1) == p.charAt(j-2) || p.charAt(j-2) == '.') && dp[i-1][j]);
17+
dp[i][j] = dp[i][j-2] || ((s.charAt(i-1) == p.charAt(j-2) || p.charAt(j-2) == '.') && dp[i-1][j]);
1718
}
1819
}
1920
return dp[s.length()][p.length()];
2021
}
21-
}
22+
}

0 commit comments

Comments
 (0)