|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>给定一个字符串 (<code>s</code>) 和一个字符模式 (<code>p</code>) ,实现一个支持 <code>'?'</code> 和 <code>'*'</code> 的通配符匹配。</p> |
10 |
| - |
11 |
| -<pre>'?' 可以匹配任何单个字符。 |
12 |
| -'*' 可以匹配任意字符串(包括空字符串)。 |
13 |
| -</pre> |
14 |
| - |
15 |
| -<p>两个字符串<strong>完全匹配</strong>才算匹配成功。</p> |
16 |
| - |
17 |
| -<p><strong>说明:</strong></p> |
| 9 | +<div class="title__3Vvk">给你一个输入字符串 (<code>s</code>) 和一个字符模式 (<code>p</code>) ,请你实现一个支持 <code>'?'</code> 和 <code>'*'</code> 匹配规则的通配符匹配:</div> |
18 | 10 |
|
19 | 11 | <ul>
|
20 |
| - <li><code>s</code> 可能为空,且只包含从 <code>a-z</code> 的小写字母。</li> |
21 |
| - <li><code>p</code> 可能为空,且只包含从 <code>a-z</code> 的小写字母,以及字符 <code>?</code> 和 <code>*</code>。</li> |
| 12 | + <li class="title__3Vvk"><code>'?'</code> 可以匹配任何单个字符。</li> |
| 13 | + <li class="title__3Vvk"><code>'*'</code> 可以匹配任意字符序列(包括空字符序列)。</li> |
22 | 14 | </ul>
|
23 | 15 |
|
24 |
| -<p><strong>示例 1:</strong></p> |
| 16 | +<div class="original__bRMd"> |
| 17 | +<div> |
| 18 | +<p>判定匹配成功的充要条件是:字符模式必须能够 <strong>完全匹配</strong> 输入字符串(而不是部分匹配)。</p> |
| 19 | +</div> |
| 20 | +</div> |
| 21 | + |
25 | 22 |
|
26 |
| -<pre><strong>输入:</strong> |
27 |
| -s = "aa" |
28 |
| -p = "a" |
29 |
| -<strong>输出:</strong> false |
30 |
| -<strong>解释:</strong> "a" 无法匹配 "aa" 整个字符串。</pre> |
| 23 | +<p><strong class="example">示例 1:</strong></p> |
31 | 24 |
|
32 |
| -<p><strong>示例 2:</strong></p> |
33 |
| - |
34 |
| -<pre><strong>输入:</strong> |
35 |
| -s = "aa" |
36 |
| -p = "*" |
37 |
| -<strong>输出:</strong> true |
38 |
| -<strong>解释:</strong> '*' 可以匹配任意字符串。 |
| 25 | +<pre> |
| 26 | +<strong>输入:</strong>s = "aa", p = "a" |
| 27 | +<strong>输出:</strong>false |
| 28 | +<strong>解释:</strong>"a" 无法匹配 "aa" 整个字符串。 |
39 | 29 | </pre>
|
40 | 30 |
|
41 |
| -<p><strong>示例 3:</strong></p> |
| 31 | +<p><strong class="example">示例 2:</strong></p> |
42 | 32 |
|
43 |
| -<pre><strong>输入:</strong> |
44 |
| -s = "cb" |
45 |
| -p = "?a" |
46 |
| -<strong>输出:</strong> false |
47 |
| -<strong>解释:</strong> '?' 可以匹配 'c', 但第二个 'a' 无法匹配 'b'。 |
| 33 | +<pre> |
| 34 | +<strong>输入:</strong>s = "aa", p = "*" |
| 35 | +<strong>输出:</strong>true |
| 36 | +<strong>解释:</strong>'*' 可以匹配任意字符串。 |
48 | 37 | </pre>
|
49 | 38 |
|
50 |
| -<p><strong>示例 4:</strong></p> |
| 39 | +<p><strong class="example">示例 3:</strong></p> |
51 | 40 |
|
52 |
| -<pre><strong>输入:</strong> |
53 |
| -s = "adceb" |
54 |
| -p = "*a*b" |
55 |
| -<strong>输出:</strong> true |
56 |
| -<strong>解释:</strong> 第一个 '*' 可以匹配空字符串, 第二个 '*' 可以匹配字符串 "dce". |
| 41 | +<pre> |
| 42 | +<strong>输入:</strong>s = "cb", p = "?a" |
| 43 | +<strong>输出:</strong>false |
| 44 | +<strong>解释:</strong>'?' 可以匹配 'c', 但第二个 'a' 无法匹配 'b'。 |
57 | 45 | </pre>
|
58 | 46 |
|
59 |
| -<p><strong>示例 5:</strong></p> |
| 47 | +<p> </p> |
| 48 | + |
| 49 | +<p><strong>提示:</strong></p> |
60 | 50 |
|
61 |
| -<pre><strong>输入:</strong> |
62 |
| -s = "acdcb" |
63 |
| -p = "a*c?b" |
64 |
| -<strong>输出:</strong> false</pre> |
| 51 | +<ul> |
| 52 | + <li><code>0 <= s.length, p.length <= 2000</code></li> |
| 53 | + <li><code>s</code> 仅由小写英文字母组成</li> |
| 54 | + <li><code>p</code> 仅由小写英文字母、<code>'?'</code> 或 <code>'*'</code> 组成</li> |
| 55 | +</ul> |
65 | 56 |
|
66 | 57 | ## 解法
|
67 | 58 |
|
|
0 commit comments