-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path44_wildcardMatching.py
More file actions
32 lines (30 loc) · 910 Bytes
/
44_wildcardMatching.py
File metadata and controls
32 lines (30 loc) · 910 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:
# @param s, an input string
# @param p, a pattern string
# @return a boolean
def isMatch(self, s, p):
s_cur = 0
p_cur = 0
match = 0
star = -1
while s_cur < len(s):
if p_cur < len(p) and (s[s_cur] == p[p_cur] or p[p_cur] == '?'):
s_cur = s_cur + 1
p_cur = p_cur + 1
elif p_cur < len(p) and p[p_cur] == '*':
match = s_cur
star = p_cur
p_cur = p_cur+1
elif (star != -1):
p_cur = star+1
match = match+1
s_cur = match
else:
return False
while p_cur < len(p) and p[p_cur] == '*':
p_cur = p_cur+1
if p_cur == len(p):
return True
else:
return False
print(Solution().isMatch('abed', '?b*d**'))