###### Hard-题目51：44. Wildcard Matching

Implement wildcard pattern matching with support for ‘?’ and ‘*’.

‘?’ Matches any single character.
‘*’ Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).

The function prototype should be:
bool isMatch(const char *s, const char *p)

Some examples:
isMatch(“aa”,”a”) → false
isMatch(“aa”,”aa”) → true
isMatch(“aaa”,”aa”) → false
isMatch(“aa”, “*”) → true
isMatch(“aa”, “a*”) → true
isMatch(“ab”, “?*”) → true
isMatch(“aab”, “c*a*b”) → false

Loop
keep two pointers in S and P here i and j
if S[i] == P[j] or P[j] == ‘?’ we keep moving
if ‘*’ exist in P then we mark the position in P as star and mark position in s as s_star
Loop over s until S[i] == P[star + 1] otherwise False

class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
i = 0
j = 0
star = -1
s_star = 0
s_len = len(s)
p_len = len(p)
while i < s_len:
if i < s_len and j < p_len and (s[i] == p[j] or p[j] == '?'):
i += 1
j += 1
elif j < p_len and p[j] == '*':
star = j
s_star = i
j += 1
elif star != -1:
j = star + 1
s_star += 1
i = s_star
else:
return False
while j < p_len and p[j] == '*':
j += 1
return j == p_len

116ms,85.49%,124ms,7.50%
cmershen的碎碎念：

#### LeetCode --- 44. Wildcard Matching

2015-02-10 08:58:41

#### 【LeetCode】【C++】Wildcard Matching

2015-03-21 11:21:59

#### LeetCode 44. Wildcard Matching（模糊匹配）

2016-05-21 04:07:39

#### [leetcode-44]Wildcard Matching(java)

2015-10-13 15:18:03

#### 44. Wildcard Matching Leetcode Python

2015-03-27 07:19:45

#### LeetCode(44) Wildcard Matching

2015-01-04 15:26:39

#### (Java)LeetCode-44.Wildcard Matching

2016-09-20 15:46:35

#### LeetCode（44） Wildcard Matching

2015-12-15 14:51:07

#### LeetCode题目：44. Wildcard Matching

2017-11-21 23:15:12

#### [Leetcode] 44. Wildcard Matching

2015-03-16 21:40:57

## 不良信息举报

Hard-题目51：44. Wildcard Matching