-
Notifications
You must be signed in to change notification settings - Fork 481
/
0044.py
33 lines (30 loc) · 817 Bytes
/
0044.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution:
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
s_len, p_len = len(s), len(p)
i, j, star, i_index = 0, 0, -1, 0
while i < s_len:
if j < p_len and (p[j] == '?' or p[j] == s[i]):
i += 1
j += 1
elif j < p_len and p[j] == '*':
star = j
j += 1
i_index = i
elif star != -1:
j = star + 1
i_index += 1
i = i_index
else:
return False
while j < p_len and p[j] == '*':
j += 1
return j == p_len
if __name__ == "__main__":
s = "aa"
p = "*"
print(Solution().isMatch(s, p))