-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path44.py
More file actions
32 lines (28 loc) · 743 Bytes
/
44.py
File metadata and controls
32 lines (28 loc) · 743 Bytes
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
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
si, pi, sj, pj = 0,0,-1,-1
while si<len(s):
if pi<len(p) and (s[si]==p[pi] or p[pi]=='?'):
pi+=1
si+=1
elif pi<len(p) and p[pi]=='*':
pi += 1
pj = pi
sj = si
elif pj>=0:
sj += 1
si = sj
pi = pj
else:
return False
while pi<len(p) and p[pi] == '*':
pi += 1
return pi == len(p)
if __name__ == '__main__':
solution = Solution()
print solution.isMatch("", "*")