{"id":2901,"date":"2020-02-08T14:00:49","date_gmt":"2020-02-08T06:00:49","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2901"},"modified":"2020-02-08T14:00:49","modified_gmt":"2020-02-08T06:00:49","slug":"%e3%80%90leetcode%e3%80%910044-%e9%80%9a%e9%85%8d%e7%ac%a6%e5%8c%b9%e9%85%8d","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2901\/","title":{"rendered":"\u3010LeetCode\u30110044 \u901a\u914d\u7b26\u5339\u914d"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/wildcard-matching\/\">https:\/\/leetcode-cn.com\/problems\/wildcard-matching\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def isMatch(self, s, p):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> s: str\n        <\/em><strong><em>:type<\/em><\/strong><em> p: str\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: bool\n        \"\"\"\n        <\/em>sn = len(s)\n        pn = len(p)\n        dp = [[False] * (pn + 1) for _ in range(sn + 1)]\n        dp[0][0] = True\n        for j in range(1, pn + 1):\n            if p[j - 1] == \"*\":\n                dp[0][j] = dp[0][j - 1]\n        for i in range(1, sn + 1):\n            for j in range(1, pn + 1):\n                if (s[i - 1] == p[j - 1] or p[j - 1] == \"?\"):\n                    dp[i][j] = dp[i - 1][j - 1]\n                elif p[j - 1] == \"*\":\n                    dp[i][j] = dp[i - 1][j] or dp[i][j - 1]\n        return dp[-1][-1]\nif __name__ == '__main__':\n    s = 'acdcb'\n    p = 'a*c?b'\n    print(Solution().isMatch(s, p))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u4e0d\u5f97\u4e0d\u8bf4\uff0c\u52a8\u6001\u89c4\u5212\u786e\u5b9e\u9700\u8981\u591a\u505a\u505a\u9898\uff0c\u8fd9\u9053\u9898\u660e\u660e\u77e5\u9053\u662f\u52a8\u6001\u89c4\u5212\uff0c\u53ef\u662f\u4e2d\u95f4\u72b6\u6001\u4f9d\u7136\u627e\u4e0d\u5230\uff0c\u8fd9\u79cd\u95ee\u9898\u524d\u9762\u5df2\u7ecf\u51fa\u73b0\u8fc7\u4e86\u3002<\/p>\n\n\n<p>\u5982\u679ci,j\u5339\u914d\u5219\u5f53\u524d\u72b6\u6001\u7b49\u4e8ei-1,j-1\u7684\u72b6\u6001\uff0c\u5982\u679c\u662f*\u5219\u8bf4\u660e\u5f53\u524d\u7684\u72b6\u6001\u662fi-1,j\uff08*\u5339\u914d\u7a7a\uff09\u6216\u8005i,j-1\uff08*\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\uff09\u4e2d\u7684\u4e00\u4e2a\u3002<\/p>\n\n\n<p>\u52a8\u6001\u89c4\u5212\u5217\u8868\u5982\u4e0b<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"251\" height=\"129\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-33.png\" alt=\"\" class=\"wp-image-2902\"\/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/wildcard-matching [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[10],"tags":[],"views":1709,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2901"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2901"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2901\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2901"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}