{"id":2182,"date":"2022-01-21T09:31:29","date_gmt":"2022-01-21T01:31:29","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2182"},"modified":"2022-01-21T09:54:55","modified_gmt":"2022-01-21T01:54:55","slug":"leetcodeday44","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/21\/leetcodeday44\/","title":{"rendered":"leetcodeday44 &#8211;\u901a\u914d\u7b26\u5339\u914d"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;(<code>s<\/code>) \u548c\u4e00\u4e2a\u5b57\u7b26\u6a21\u5f0f&nbsp;(<code>p<\/code>) \uff0c\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301&nbsp;<code>'?'<\/code>&nbsp;\u548c&nbsp;<code>'*'<\/code>&nbsp;\u7684\u901a\u914d\u7b26\u5339\u914d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'?' \u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002\n'*' \u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\uff08\u5305\u62ec\u7a7a\u5b57\u7b26\u4e32\uff09\u3002<\/code><\/pre>\n\n\n\n<p>\u4e24\u4e2a\u5b57\u7b26\u4e32<strong>\u5b8c\u5168\u5339\u914d<\/strong>\u624d\u7b97\u5339\u914d\u6210\u529f\u3002<\/p>\n\n\n\n<p><strong>\u8bf4\u660e:<\/strong><\/p>\n\n\n\n<ul><li><code>s<\/code>&nbsp;\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece&nbsp;<code>a-z<\/code>&nbsp;\u7684\u5c0f\u5199\u5b57\u6bcd\u3002<\/li><li><code>p<\/code>&nbsp;\u53ef\u80fd\u4e3a\u7a7a\uff0c\u4e14\u53ea\u5305\u542b\u4ece&nbsp;<code>a-z<\/code>&nbsp;\u7684\u5c0f\u5199\u5b57\u6bcd\uff0c\u4ee5\u53ca\u5b57\u7b26&nbsp;<code>?<\/code>&nbsp;\u548c&nbsp;<code>*<\/code>\u3002<\/li><\/ul>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>\ns = \"aa\"\np = \"a\"\n<strong>\u8f93\u51fa:<\/strong> false\n<strong>\u89e3\u91ca:<\/strong> \"a\" \u65e0\u6cd5\u5339\u914d \"aa\" \u6574\u4e2a\u5b57\u7b26\u4e32\u3002<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>\ns = \"aa\"\np = \"*\"\n<strong>\u8f93\u51fa:<\/strong> true\n<strong>\u89e3\u91ca:<\/strong>&nbsp;'*' \u53ef\u4ee5\u5339\u914d\u4efb\u610f\u5b57\u7b26\u4e32\u3002<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;3:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>\ns = \"cb\"\np = \"?a\"\n<strong>\u8f93\u51fa:<\/strong> false\n<strong>\u89e3\u91ca:<\/strong>&nbsp;'?' \u53ef\u4ee5\u5339\u914d 'c', \u4f46\u7b2c\u4e8c\u4e2a 'a' \u65e0\u6cd5\u5339\u914d 'b'\u3002<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;4:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>\ns = \"adceb\"\np = \"*a*b\"\n<strong>\u8f93\u51fa:<\/strong> true\n<strong>\u89e3\u91ca:<\/strong>&nbsp;\u7b2c\u4e00\u4e2a '*' \u53ef\u4ee5\u5339\u914d\u7a7a\u5b57\u7b26\u4e32, \u7b2c\u4e8c\u4e2a '*' \u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32 \"dce\".<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;5:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165:<\/strong>\ns = \"acdcb\"\np = \"a*c?b\"\n<strong>\u8f93\u51fa:<\/strong> false<\/code><\/pre>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u601d\u8def\uff1a\u56de\u6eaf\u7b97\u6cd5\uff08N\u53c9\u6811\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc code=start\nclass Solution:\n    def isMatch(self,s: str, p: str) -&gt; bool:\n        if s==\"\" and p==\"\":\n            return True\n        if p==\"\":\n            return False\n        len1=len(s)\n        n1=0\n        m1=\"\"\n        len2=len(p)\n        for i in range(1,len2):\n            if p&#91;i]==\"*\" and p&#91;i-1]==\"*\":\n                continue\n            else : \n                m1=m1+p&#91;i-1]\n                n1=1+n1\n        p=m1+p&#91;-1]\n        len2=len(p)\n        def submacth(i,j):\n            if i==len1 and j==len2:\n                return True\n            if j==len2:\n                return False\n            if i==len1 and (p&#91;j:]!=\"*\"*len(p&#91;j:])):\n                #print(False)\n                return False\n            if p&#91;j]!=\"*\" :\n                if p&#91;j]==\"?\"or p&#91;j]==s&#91;i]:\n                    i=i+1\n                    j=j+1\n                    return submacth(i,j)\n\n                else:\n                    #print(False)\n                    return False\n            if p&#91;j]==\"*\" and j==len2-1:\n                    #print(\"3333\")\n                    l=len1\n                    h=len2\n                    return submacth(l,h)\n                        \n            if p&#91;j]==\"*\" and j&lt;len2-1:\n                for m in range(i,len1):\n                    if s&#91;m]==p&#91;j+1] or p&#91;j+1]==\"?\":\n                        #print(m,j+1,\"hh\")\n                        l=m+1\n                        h=j+2\n                        if submacth(l,h):\n                            return True\n                return False\n\n        return submacth(0,0)<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-248.png\" alt=\"\" class=\"wp-image-2184\" width=\"467\" height=\"351\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-248.png 685w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-248-300x226.png 300w\" sizes=\"(max-width: 467px) 100vw, 467px\" \/><\/figure><\/div>\n\n\n\n<p>\u9700\u6539\u8fdb\uff1a<\/p>\n\n\n\n<p>\u52a8\u6001\u89c4\u5212\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ul><li>\u786e\u5b9adp[i][j]\u72b6\u6001\u542b\u4e49<\/li><li>\u786e\u5b9a \u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b<\/li><li>\u786e\u5b9adp\u521d\u59cb\u503c<\/li><\/ul>\n\n\n\n<p>\u53c2\u8003\u5b98\u65b9\u9898\u89e3\uff1a\u52a8\u6001\u89c4\u5212\u95ee\u9898dp[i][j]\u8868\u793as\u7684\u524di\u4e2a\u5b57\u7b26\u548c p\u7684\u524dj\u4e2a\u5b57\u7b26\u662f\u5426\u5339\u914d\u3002\u5728\u8fdb\u884c\u72b6\u6001\u8f6c\u79fb\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u6a21\u5f0f&nbsp;<em>p<\/em>&nbsp;\u7684\u7b2c&nbsp;<em>j<\/em>&nbsp;\u4e2a\u5b57\u7b26&nbsp;<em>pj<\/em>\u200b\uff0c\u4e0e\u4e4b\u5bf9\u5e94\u7684\u662f\u5b57\u7b26\u4e32&nbsp;<em>s<\/em>&nbsp;\u4e2d\u7684\u7b2c&nbsp;<em>i<\/em>&nbsp;\u4e2a\u5b57\u7b26<em>si<\/em>\u200b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"631\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-250-1024x631.png\" alt=\"\" class=\"wp-image-2193\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-250-1024x631.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-250-300x185.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-250-768x473.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-250.png 1283w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"387\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-251-1024x387.png\" alt=\"\" class=\"wp-image-2194\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-251-1024x387.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-251-300x113.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-251-768x290.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-251.png 1260w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" width=\"1024\" height=\"601\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-252-1024x601.png\" alt=\"\" class=\"wp-image-2195\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-252-1024x601.png 1024w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-252-300x176.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-252-768x451.png 768w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-252.png 1276w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>class Solution:\n    def isMatch(self, s: str, p: str) -&gt; bool:\n        m, n = len(s), len(p)\n\n        dp = &#91;&#91;False] * (n + 1) for _ in range(m + 1)]\n        dp&#91;0]&#91;0] = True\n        for i in range(1, n + 1):\n            if p&#91;i - 1] == '*':\n                dp&#91;0]&#91;i] = True\n            else:\n                break\n        \n        for i in range(1, m + 1):\n            for j in range(1, n + 1):\n                if p&#91;j - 1] == '*':\n                    dp&#91;i]&#91;j] = dp&#91;i]&#91;j - 1] | dp&#91;i - 1]&#91;j]\n                elif p&#91;j - 1] == '?' or s&#91;i - 1] == p&#91;j - 1]:\n                    dp&#91;i]&#91;j] = dp&#91;i - 1]&#91;j - 1]\n                \n        return dp&#91;m]&#91;n]<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-249.png\" alt=\"\" class=\"wp-image-2190\" width=\"535\" height=\"150\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-249.png 819w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-249-300x85.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-249-768x217.png 768w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;(s) \u548c\u4e00\u4e2a\u5b57\u7b26\u6a21\u5f0f&nbsp;(p) \uff0c\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301&nbsp;&#8216;?&#8217;&#038;nbsp &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/21\/leetcodeday44\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday44 &#8211;\u901a\u914d\u7b26\u5339\u914d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2182"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2182"}],"version-history":[{"count":11,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2182\/revisions"}],"predecessor-version":[{"id":2200,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2182\/revisions\/2200"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2182"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}