Skip to content

Commit d4c465b

Browse files
refactor 10
1 parent ec154d1 commit d4c465b

File tree

1 file changed

+8
-8
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+8
-8
lines changed

src/main/java/com/fishercoder/solutions/_10.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package com.fishercoder.solutions;
22

33
/**
4+
* 10. Regular Expression Matching
5+
*
46
* Implement regular expression matching with support for '.' and '*'.
5-
*

7+
*
68
* '.' Matches any single character.
79
* '*' Matches zero or more of the preceding element.
8-
*

10+
*
911
* The matching should cover the entire input string (not partial).
10-
*

12+
*
1113
* The function prototype should be:
1214
* bool isMatch(const char *s, const char *p)
13-
*

15+
*
1416
* Some examples:
1517
* isMatch("aa","a") → false
1618
* isMatch("aa","aa") → true
@@ -20,6 +22,7 @@
2022
* isMatch("ab", ".*") → true
2123
* isMatch("aab", "c*a*b") → true
2224
*/
25+
2326
public class _10 {
2427

2528
public boolean isMatch(String s, String p) {
@@ -35,10 +38,7 @@ public boolean isMatch(String s, String p) {
3538
}
3639
for (int i = 0; i < s.length(); i++) {
3740
for (int j = 0; j < p.length(); j++) {
38-
if (p.charAt(j) == '.') {
39-
dp[i + 1][j + 1] = dp[i][j];
40-
}
41-
if (p.charAt(j) == s.charAt(i)) {
41+
if (p.charAt(j) == '.' || p.charAt(j) == s.charAt(i)) {
4242
dp[i + 1][j + 1] = dp[i][j];
4343
}
4444
if (p.charAt(j) == '*') {

0 commit comments

Comments
 (0)