File tree 1 file changed +10
-9
lines changed
scripts/algorithms/W/Wildcard Matching
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 2 ms (Top 100.00%) | Memory: 42.3 MB (Top 99.02%)
1
2
class Solution {
2
3
public boolean isMatch (String s , String p ) {
3
4
int i =0 ;
4
5
int j =0 ;
5
6
int starIdx =-1 ;
6
7
int lastMatch =-1 ;
7
-
8
+
8
9
while (i <s .length ()){
9
- if (j <p .length () && (s .charAt (i )==p .charAt (j ) ||
10
+ if (j <p .length () && (s .charAt (i )==p .charAt (j ) ||
10
11
p .charAt (j )=='?' )){
11
12
i ++;
12
13
j ++;
@@ -18,19 +19,19 @@ public boolean isMatch(String s, String p) {
18
19
//there is a no match and there was a previous star, we will reset the j to indx after star_index
19
20
//lastMatch will tell from which index we start comparing the string if we encounter * in pattern
20
21
j =starIdx +1 ;
21
- lastMatch ++; // we are saying we included more characters in * so we incremented the index
22
+ lastMatch ++; // we are saying we included more characters in * so we incremented the index
22
23
i =lastMatch ;
23
-
24
+
24
25
}else {
25
26
return false ;
26
27
}
27
28
}
28
-
29
+
29
30
while (j <p .length () && p .charAt (j )=='*' ) j ++;
30
-
31
+
31
32
if (i !=s .length () || j !=p .length ()) return false ;
32
-
33
+
33
34
return true ;
34
-
35
+
35
36
}
36
- }
37
+ }
You can’t perform that action at this time.
0 commit comments