Skip to content

Commit 47aabc6

Browse files
committed
Runtime: 2 ms (Top 100.00%) | Memory: 42.3 MB (Top 99.02%)
1 parent f8bc395 commit 47aabc6

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
// Runtime: 2 ms (Top 100.00%) | Memory: 42.3 MB (Top 99.02%)
12
class Solution {
23
public boolean isMatch(String s, String p) {
34
int i=0;
45
int j=0;
56
int starIdx=-1;
67
int lastMatch=-1;
7-
8+
89
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) ||
1011
p.charAt(j)=='?')){
1112
i++;
1213
j++;
@@ -18,19 +19,19 @@ public boolean isMatch(String s, String p) {
1819
//there is a no match and there was a previous star, we will reset the j to indx after star_index
1920
//lastMatch will tell from which index we start comparing the string if we encounter * in pattern
2021
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
2223
i=lastMatch;
23-
24+
2425
}else{
2526
return false;
2627
}
2728
}
28-
29+
2930
while(j<p.length() && p.charAt(j)=='*') j++;
30-
31+
3132
if(i!=s.length() || j!=p.length()) return false;
32-
33+
3334
return true;
34-
35+
3536
}
36-
}
37+
}

0 commit comments

Comments
 (0)