{"id":2084,"date":"2022-01-15T18:31:19","date_gmt":"2022-01-15T10:31:19","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2084"},"modified":"2022-01-15T20:55:10","modified_gmt":"2022-01-15T12:55:10","slug":"leetcodeday32","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/15\/leetcodeday32\/","title":{"rendered":"leetcodeday32 &#8212;\u6700\u957f\u6709\u6548\u62ec\u53f7"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b&nbsp;<code>'('<\/code>&nbsp;\u548c&nbsp;<code>')'<\/code>&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u627e\u51fa\u6700\u957f\u6709\u6548\uff08\u683c\u5f0f\u6b63\u786e\u4e14\u8fde\u7eed\uff09\u62ec\u53f7\u5b50\u4e32\u7684\u957f\u5ea6\u3002<\/p>\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>2\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u957f\u6709\u6548\u62ec\u53f7\u5b50\u4e32\u662f \"()\"\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 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>4\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6700\u957f\u6709\u6548\u62ec\u53f7\u5b50\u4e32\u662f \"()()\"\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 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>0\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>0 &lt;= s.length &lt;= 3 * 10<sup>4<\/sup><\/code><\/li><li><code>s[i]<\/code>&nbsp;\u4e3a&nbsp;<code>'('<\/code>&nbsp;\u6216&nbsp;<code>')'<\/code><\/li><\/ul>\n\n\n\n<p>\u601d\u8def\uff1a\u8bb0\u5f55\u6bcf\u4e2a\u6253\u7834\u6210\u5bf9\u62ec\u53f7\u89c4\u5219\u7684\u4f4d\u7f6e\uff0c\u90a3\u4e48\u6700\u957f\u7684\u7b26\u5408\u8981\u6c42\u7684\u957f\u5ea6\u5c31\u5728\u8fd9\u4e9b\u4f4d\u7f6e\u4e4b\u95f4 \u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\n# @lc code=start\nclass Solution:\r\n    def longestValidParentheses(self,s: str) -> int:\r\n        if s==\"\":\r\n            return 0\r\n        length = len(s)\r\n        rev,div=list(),list()\r\n        i=0\r\n        lens=0\r\n        result=0\r\n        while i&lt;=length-1:\r\n            lens=len(rev)\r\n            if s&#91;i]==\"(\": \r\n                rev.append(s&#91;i])\r\n                div.append(i)\r\n                \r\n\r\n            elif lens!=0 and s&#91;i]==\")\": \r\n                rev.pop()\r\n                #result=mid if mid  >=result else result\r\n                div.pop()\r\n                \r\n            else:\r\n                div.append(i)\r\n                #result=mid if mid  >=result else result\r\n            i=i+1   \r\n\r\n        \r\n        res=list()\r\n        if div.count(length)==0:\r\n            div.append(length)\r\n        res.append(div&#91;0])\r\n        if len(div)>1:\r\n            for i in range(1,len(div)):\r\n                res.append(div&#91;i]-div&#91;i-1]-1)\r\n\r\n        return max(res) if max(res)>result else result\r\n            <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"909\" height=\"167\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-229.png\" alt=\"\" class=\"wp-image-2086\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-229.png 909w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-229-300x55.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-229-768x141.png 768w\" sizes=\"(max-width: 909px) 100vw, 909px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u53ea\u5305\u542b&nbsp;&#8216;(&#8216;&nbsp;\u548c&nbsp;&#8216;)&#8217;&nbsp;\u7684\u5b57\u7b26\u4e32\uff0c\u627e\u51fa\u6700\u957f\u6709\u6548\uff08\u683c\u5f0f\u6b63\u786e\u4e14 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/15\/leetcodeday32\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday32 &#8212;\u6700\u957f\u6709\u6548\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\/2084"}],"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=2084"}],"version-history":[{"count":6,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2084\/revisions"}],"predecessor-version":[{"id":2091,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2084\/revisions\/2091"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2084"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}