File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
3
/**
4
+ * 10. Regular Expression Matching
5
+ *
4
6
* Implement regular expression matching with support for '.' and '*'.
5
-
7
+ *
6
8
* '.' Matches any single character.
7
9
* '*' Matches zero or more of the preceding element.
8
-
10
+ *
9
11
* The matching should cover the entire input string (not partial).
10
-
12
+ *
11
13
* The function prototype should be:
12
14
* bool isMatch(const char *s, const char *p)
13
-
15
+ *
14
16
* Some examples:
15
17
* isMatch("aa","a") → false
16
18
* isMatch("aa","aa") → true
20
22
* isMatch("ab", ".*") → true
21
23
* isMatch("aab", "c*a*b") → true
22
24
*/
25
+
23
26
public class _10 {
24
27
25
28
public boolean isMatch (String s , String p ) {
@@ -35,10 +38,7 @@ public boolean isMatch(String s, String p) {
35
38
}
36
39
for (int i = 0 ; i < s .length (); i ++) {
37
40
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 )) {
42
42
dp [i + 1 ][j + 1 ] = dp [i ][j ];
43
43
}
44
44
if (p .charAt (j ) == '*' ) {
You can’t perform that action at this time.
0 commit comments