{"id":2029,"date":"2022-01-14T11:17:48","date_gmt":"2022-01-14T03:17:48","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2029"},"modified":"2022-01-14T11:17:51","modified_gmt":"2022-01-14T03:17:51","slug":"leetcodeday20","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/14\/leetcodeday20\/","title":{"rendered":"leetcodeday20 &#8212;\u6709\u6548\u7684\u62ec\u53f7"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u62ec&nbsp;<code>'('<\/code>\uff0c<code>')'<\/code>\uff0c<code>'{'<\/code>\uff0c<code>'}'<\/code>\uff0c<code>'['<\/code>\uff0c<code>']'<\/code>&nbsp;\u7684\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\uff0c\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u6709\u6548\u3002<\/p>\n\n\n\n<p>\u6709\u6548\u5b57\u7b26\u4e32\u9700\u6ee1\u8db3\uff1a<\/p>\n\n\n\n<ol><li>\u5de6\u62ec\u53f7\u5fc5\u987b\u7528\u76f8\u540c\u7c7b\u578b\u7684\u53f3\u62ec\u53f7\u95ed\u5408\u3002<\/li><li>\u5de6\u62ec\u53f7\u5fc5\u987b\u4ee5\u6b63\u786e\u7684\u987a\u5e8f\u95ed\u5408\u3002<\/li><\/ol>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"()\"\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"()[]{}\"\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"(]\"\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;4\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"([)]\"\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b&nbsp;5\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"{[]}\"\n<strong>\u8f93\u51fa\uff1a<\/strong>true<\/pre>\n\n\n\n<p>\u601d\u8def\uff1a\u4f7f\u7528\u6808\uff0c\u5148\u5165\u6808\uff0c\u6bcf\u5f53\u8fdb\u5165\u4e00\u4e2a\u5143\u7d20\uff0c\u5224\u65ad\u662f\u5426\u548c\u4e0a\u4e00\u4e2a\u5339\u914d\uff0c\u5982\u679c\u5339\u914d\uff0c\u4ed6\u4eec\u4e24\u4e2a\u51fa\u6808\uff0c\u5982\u679c\u62ec\u53f7\u65b9\u6cd5\u76f8\u53cd\uff0c\u76f4\u63a5\u8fd4\u56defalse\uff0c\u5982\u679c\u62ec\u53f7\u65b9\u5411\u76f8\u540c\uff0c\u7ee7\u7eed\u4e0b\u4e00\u5143\u7d20\u5165\u6808\uff0c\u77e5\u9053\u5168\u90e8\u90fd\u5165\u6808\uff0c\u5982\u679c\u6808\u4e0d\u7a7a\uff0c\u8fd4\u56defalse<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\n# @lc code=start\r\nclass Solution:\r\n    def isValid(self, s: str) -> bool:\r\n        lens=len(s)\r\n        sets={\"(\":\")\",\"{\":\"}\",\"&#91;\":\"]\"}\r\n        left=&#91;\"(\",\"&#91;\",\"{\"]\r\n        lists=list()\r\n        lists.append(s&#91;0])\r\n        j=1\r\n        while  j&lt;=lens-1:\r\n            if lists==&#91;]:\r\n                lists.append(s&#91;j])\r\n                j=j+1\r\n                continue\r\n            elif lists&#91;-1] not in left:\r\n                print(lists)\r\n                return False\r\n            elif sets&#91;lists&#91;-1]]==s&#91;j]:\r\n                j=j+1\r\n                lists.pop()\r\n               \r\n            else:\r\n                lists.append(s&#91;j])\r\n                j=j+1\r\n        print(lists)\r\n        return True if lists==&#91;] else False<\/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-216.png\" alt=\"\" class=\"wp-image-2031\" width=\"444\" height=\"130\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-216.png 664w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-216-300x88.png 300w\" sizes=\"(max-width: 444px) 100vw, 444px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u62ec&nbsp;&#8216;(&#8216;\uff0c&#8217;)&#8217;\uff0c'{&#8216;\uff0c&#8217;}&#8217;\uff0c'[&#8216;\uff0c&#8217;]&#8217;&nbsp;\u7684\u5b57\u7b26\u4e32&nbsp;s&#038;n &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/14\/leetcodeday20\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday20 &#8212;\u6709\u6548\u7684\u62ec\u53f7<\/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\/2029"}],"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=2029"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2029\/revisions"}],"predecessor-version":[{"id":2032,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2029\/revisions\/2032"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2029"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}