{"id":2775,"date":"2020-01-14T11:44:23","date_gmt":"2020-01-14T03:44:23","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2775"},"modified":"2020-01-14T11:44:23","modified_gmt":"2020-01-14T03:44:23","slug":"%e3%80%90leetcode%e3%80%910010-%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%8c%b9%e9%85%8d","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2775\/","title":{"rendered":"\u3010LeetCode\u30110010 \u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/regular-expression-matching\/\">https:\/\/leetcode-cn.com\/problems\/regular-expression-matching\/<\/a><\/p>\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<br \/>class Solution(object):<br \/>    def isMatch(self, s, p):<br \/>        <em>\"\"\"<br \/><\/em><em>        <\/em><strong><em>:type<\/em><\/strong><em> s: str<br \/><\/em><em>        <\/em><strong><em>:type<\/em><\/strong><em> p: str<br \/><\/em><em>        <\/em><strong><em>:rtype<\/em><\/strong><em>: bool<br \/><\/em><em>        \"\"\"<br \/><\/em><em>        <\/em>if len(p) &lt;= 0:<br \/>            return len(s) &lt;= 0<br \/>        match = len(s) &gt; 0 and (s[0] == p[0] or p[0] == '.')<br \/>        if len(p) &gt; 1 and p[1] == '*':<br \/>            # \u5bf9\u5e94*\u662f\u65e0\u7528\u7684\uff08\u4e5f\u5c31\u662f0\u6b21\uff09   \u548c    *\u662f\u6709\u7528\u7684<br \/>            return self.isMatch(s, p[2:]) or (match and self.isMatch(s[1:], p))<br \/>        else:<br \/>            return match and self.isMatch(s[1:], p[1:])<br \/><br \/><br \/>if __name__ == '__main__':<br \/>    s = 'aaa'<br \/>    p = 'ab*a*c*a'<br \/>    s = 'mississippi'<br \/>    p = 'mis*is*p*.'<br \/>    print(Solution().isMatch(s, p))<br \/><\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u6bd4\u8f83\u660e\u663e\u7684\u662f\u7528\u52a8\u6001\u89c4\u5212\u505a\uff0c\u4f46\u662f\u6211\u4e00\u76f4\u6ca1\u627e\u5230\u5408\u9002\u7684\u72b6\u6001\u7a7a\u95f4\uff0c\u8bd5\u4e86\u51e0\u79cd\u65b9\u6cd5\uff0c\u5339\u914d\u5012\u662f\u53ef\u4ee5\u5339\u914d\uff0c\u4f46\u662f\u5bf9\u4e8e\u4e00\u4e9b\u6bd4\u5982s\u5339\u914d\u5b8cp\u8fd8\u6709\u672a\u5339\u914d\u7684\u4e00\u4e9b\u7279\u6b8a\u60c5\u51b5\u6ca1\u529e\u6cd5\u5904\u7406\uff0c\u6240\u4ee5\u9009\u62e9\u4e86\u9012\u5f52\u5904\u7406\uff0c\u8fd9\u4e2a\u5c31\u662f\u7b80\u5355\u7684\u6bcf\u6b21\u53ea\u5904\u74061\uff082\uff09\u4f4d\uff0c\u7136\u540e\u5411\u4e0b\u9012\u5f52\u76f4\u81f3\u5b57\u7b26\u4e32\u957f\u5ea6\u4e3a0\u3002<\/p>\n\n\n<p><strong>\u601d\u8003<\/strong>\uff1a\u67e5\u4e86\u67e5\u7f51\u4e0a\u7684\u8d44\u6599\uff0c\u53d1\u73b0\u4e86\u52a8\u5f52\u4e00\u76f4\u89e3\u51b3\u4e0d\u4e86\u7684\u95ee\u9898\u6240\u5728\uff0c\u6211\u5728\u5339\u914d\u7684\u65f6\u5019weight\u5217\u8868\u7528\u7684\u662f\u6574\u6570\uff0c\u4e5f\u5c31\u662f\u5f53\u524d\u5339\u914d\u957f\u5ea6\uff0c\u663e\u7136\u8fd9\u79cd\u89e3\u51b3\u65b9\u6848\u5728\u8fd9\u9053\u9898\u91cc\u662f\u4e0d\u5408\u9002\u7684\uff0c\u56e0\u4e3a\u4e00\u65e6\u67d0\u4e00\u4e2a\u4e0d\u5339\u914d\u6240\u6709\u7684\u90fd\u4e0d\u5339\u914d\uff0c\u6240\u4ee5\u5e94\u8be5\u7528True\u6216\u8005Flase\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/regular-expressio [&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":1708,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2775"}],"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=2775"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2775\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2775"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}