{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "8acf01ddd2b046fb8e4d8230e9342d2f",
  "keywords": "贪心,递归,字符串,动态规划",
  "title": "通配符匹配",
  "desc": [
    {
      "content": "\n<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>\t<li><code>s</code>&nbsp;可能为空，且只包含从&nbsp;<code>a-z</code>&nbsp;的小写字母。</li>\t<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>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution(object):\n\tdef isMatch(self, s, p):\n\t\t\"\"\"\n\t\t:type s: str\n\t\t:type p: str\n\t\t:rtype: bool\n\t\t\"\"\"\n\t\ts_index, p_index = 0, 0\n\t\tstar, s_star = -1, 0\n\t\ts_len, p_len = len(s), len(p)\n\t\twhile s_index < s_len:\n\t\t\tif p_index < p_len and (s[s_index] == p[p_index] or p[p_index] == '?'):\n\t\t\t\ts_index += 1\n\t\t\t\tp_index += 1\n\t\t\telif p_index < p_len and p[p_index] == '*':\n\t\t\t\tstar = p_index\n\t\t\t\ts_star = s_index\n\t\t\t\tp_index += 1\n\t\t\telif star != -1:\n\t\t\t\tp_index = star + 1\n\t\t\t\ts_star += 1\n\t\t\t\ts_index = s_star\n\t\t\telse:\n\t\t\t\treturn False\n\t\twhile p_index < p_len and p[p_index] == '*':\n\t\t\tp_index += 1\n\t\treturn p_index == p_len\nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.isMatch(s = \"aa\",p = \"a\"))",
    "language": "python"
  },
  "node_id": "dailycode-8d8d61cba07e4ef6bff998974a1683ea",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600471019"
}