# 通配符匹配

<p>给定一个字符串&nbsp;(<code>s</code>) 和一个字符模式&nbsp;(<code>p</code>) ，实现一个支持&nbsp;<code>&#39;?&#39;</code>&nbsp;和&nbsp;<code>&#39;*&#39;</code>&nbsp;的通配符匹配。</p><pre>&#39;?&#39; 可以匹配任何单个字符。&#39;*&#39; 可以匹配任意字符串（包括空字符串）。</pre><p>两个字符串<strong>完全匹配</strong>才算匹配成功。</p><p><strong>说明:</strong></p><ul>	<li><code>s</code>&nbsp;可能为空，且只包含从&nbsp;<code>a-z</code>&nbsp;的小写字母。</li>	<li><code>p</code>&nbsp;可能为空，且只包含从&nbsp;<code>a-z</code>&nbsp;的小写字母，以及字符&nbsp;<code>?</code>&nbsp;和&nbsp;<code>*</code>。</li></ul><p><strong>示例&nbsp;1:</strong></p><pre><strong>输入:</strong>s = &quot;aa&quot;p = &quot;a&quot;<strong><br />输出:</strong> false<strong><br />解释:</strong> &quot;a&quot; 无法匹配 &quot;aa&quot; 整个字符串。</pre><p><strong>示例&nbsp;2:</strong></p><pre><strong>输入:</strong>s = &quot;aa&quot;p = &quot;*&quot;<strong><br />输出:</strong> true<strong><br />解释:</strong>&nbsp;&#39;*&#39; 可以匹配任意字符串。</pre><p><strong>示例&nbsp;3:</strong></p><pre><strong>输入:</strong>s = &quot;cb&quot;p = &quot;?a&quot;<strong><br />输出:</strong> false<strong><br />解释:</strong>&nbsp;&#39;?&#39; 可以匹配 &#39;c&#39;, 但第二个 &#39;a&#39; 无法匹配 &#39;b&#39;。</pre><p><strong>示例&nbsp;4:</strong></p><pre><strong>输入:</strong>s = &quot;adceb&quot;p = &quot;*a*b&quot;<strong><br />输出:</strong> true<strong><br />解释:</strong>&nbsp;第一个 &#39;*&#39; 可以匹配空字符串, 第二个 &#39;*&#39; 可以匹配字符串 &quot;dce&quot;.</pre><p><strong>示例&nbsp;5:</strong></p><pre><strong>输入:</strong>s = &quot;acdcb&quot;p = &quot;a*c?b&quot;<strong><br />输出:</strong> false</pre>

以下程序实现了这一功能，请你填补空白处内容：

```python
class Solution(object):
	def isMatch(self, s, p):
		"""
		:type s: str
		:type p: str
		:rtype: bool
		"""
		s_index, p_index = 0, 0
		star, s_star = -1, 0
		s_len, p_len = len(s), len(p)
		while s_index < s_len:
			if p_index < p_len and (s[s_index] == p[p_index] or p[p_index] == '?'):
				s_index += 1
				p_index += 1
			______________________;
			elif star != -1:
				p_index = star + 1
				s_star += 1
				s_index = s_star
			else:
				return False
		while p_index < p_len and p[p_index] == '*':
			p_index += 1
		return p_index == p_len
if __name__ == '__main__':
	s = Solution()
	print (s.isMatch(s = "aa",p = "a"))
```

## template

```python
class Solution(object):
	def isMatch(self, s, p):
		"""
		:type s: str
		:type p: str
		:rtype: bool
		"""
		s_index, p_index = 0, 0
		star, s_star = -1, 0
		s_len, p_len = len(s), len(p)
		while s_index < s_len:
			if p_index < p_len and (s[s_index] == p[p_index] or p[p_index] == '?'):
				s_index += 1
				p_index += 1
			elif p_index < p_len and p[p_index] == '*':
				star = p_index
				s_star = s_index
				p_index += 1
			elif star != -1:
				p_index = star + 1
				s_star += 1
				s_index = s_star
			else:
				return False
		while p_index < p_len and p[p_index] == '*':
			p_index += 1
		return p_index == p_len
if __name__ == '__main__':
	s = Solution()
	print (s.isMatch(s = "aa",p = "a"))
```

## 答案

```python
elif p_index < p_len and p[p_index] == '*':
	star = p_index
	s_star = s_index
	p_index += 1
```

## 选项

### A

```python
elif p_index > p_len and p[p_index] == '*':
	star = p_index
	s_star = s_index
	p_index += 1
```

### B

```python
elif p_index < p_len and p[p_index] == '*':
	star = p_index
	s_star = s_index
	p_index += s_star
```

### C

```python
elif p_index > p_len and p[p_index] == '*':
	star = p_index
	s_star = s_index
	p_index += s_star
```