# 通配符匹配

<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>

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

```java
class Solution {
	public boolean isMatch(String s, String p) {
		boolean[][] value = new boolean[p.length() + 1][s.length() + 1];
		value[0][0] = true;
		for (int i = 1; i <= s.length(); i++) {
			value[0][i] = false;
		}
		for (int i = 1; i <= p.length(); i++) {
			if (p.charAt(i - 1) == '*') {
				value[i][0] = value[i - 1][0];
				for (int j = 1; j <= s.length(); j++) {
					value[i][j] = (value[i][j - 1] || value[i - 1][j]);
				}
			} else if (p.charAt(i - 1) == '?') {
				value[i][0] = false;
				for (int j = 1; j <= s.length(); j++) {
					value[i][j] = value[i - 1][j - 1];
				}
			} else {
				value[i][0] = false;
				for (int j = 1; j <= s.length(); j++) {
					____________________;
				}
			}
		}
		return value[p.length()][s.length()];
	}
}
```

## template

```java
class Solution {
	public boolean isMatch(String s, String p) {
		boolean[][] value = new boolean[p.length() + 1][s.length() + 1];
		value[0][0] = true;
		for (int i = 1; i <= s.length(); i++) {
			value[0][i] = false;
		}
		for (int i = 1; i <= p.length(); i++) {
			if (p.charAt(i - 1) == '*') {
				value[i][0] = value[i - 1][0];
				for (int j = 1; j <= s.length(); j++) {
					value[i][j] = (value[i][j - 1] || value[i - 1][j]);
				}
			} else if (p.charAt(i - 1) == '?') {
				value[i][0] = false;
				for (int j = 1; j <= s.length(); j++) {
					value[i][j] = value[i - 1][j - 1];
				}
			} else {
				value[i][0] = false;
				for (int j = 1; j <= s.length(); j++) {
					value[i][j] = s.charAt(j - 1) == p.charAt(i - 1) && value[i - 1][j - 1];
				}
			}
		}
		return value[p.length()][s.length()];
	}
}
```

## 答案

```java
value[i][j] = s.charAt(j - 1) == p.charAt(i - 1) && value[i - 1][j - 1];
```

## 选项

### A

```java
value[i][j] = s.charAt(j - 1) == p.charAt(i - 1) || value[i - 1][j - 1];
```

### B

```java
value[i][j] = s.charAt(j - 1) == p.charAt(i) && value[i - 1][j];
```

### C

```java
value[i][j] = s.charAt(j - 1) == p.charAt(i - 1) && value[i][j - 1];
```