We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d4e99e9 commit a345943Copy full SHA for a345943
src/main/java/interview/amazon/ModifiedRegex.java
@@ -34,6 +34,7 @@ public static void test() {
34
assertEquals(true, match("abcde", "....*"));
35
assertEquals(false, match("abcde", "....f"));
36
assertEquals(true, match("abcdd", "....*"));
37
+ assertEquals(true, match("abcdd", "c*.*"));
38
}
39
40
public static boolean match(String s, String p) {
@@ -46,8 +47,11 @@ public static boolean match(String s, String p, int i, int j) {
46
47
if (i >= s.length() || j >= p.length())
48
return false;
49
char sc = s.charAt(i), pc = p.charAt(j);
- if (j + 1 < p.length() && p.charAt(j + 1) == '*')
50
- return sc == pc || pc == '.' ? match(s, p, i + 1, j) || match(s, p, i + 1, j + 2) : false;
+ if (j + 1 < p.length() && p.charAt(j + 1) == '*') {
51
+ if (sc != pc && pc != '.' && match(s, p, i, j + 2))
52
+ return true;
53
+ return sc == pc || pc == '.' ? (match(s, p, i + 1, j) || match(s, p, i + 1, j + 2)) : false;
54
+ }
55
return sc == pc || pc == '.' ? match(s, p, i + 1, j + 1) : false;
56
57
0 commit comments