{"id":2832,"date":"2020-01-31T13:39:49","date_gmt":"2020-01-31T05:39:49","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2832"},"modified":"2020-01-31T13:39:49","modified_gmt":"2020-01-31T05:39:49","slug":"%e3%80%90leetcode%e3%80%910032-%e6%9c%80%e9%95%bf%e6%9c%89%e6%95%88%e6%8b%ac%e5%8f%b7","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2832\/","title":{"rendered":"\u3010LeetCode\u30110032 \u6700\u957f\u6709\u6548\u62ec\u53f7"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/longest-valid-parentheses\/\">https:\/\/leetcode-cn.com\/problems\/longest-valid-parentheses\/<\/a><\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>class Solution(object):\n    def longestValidParentheses(self, s):\n        <em>\"\"\"\n        <\/em><strong><em>:type<\/em><\/strong><em> s: str\n        <\/em><strong><em>:rtype<\/em><\/strong><em>: int\n        \"\"\"\n        <\/em>if not s:\n            return 0\n        res = 0\n        stack = [-1]\n        for i in range(len(s)):\n            if s[i] == \"(\":\n                stack.append(i)\n            else:\n                stack.pop()\n                if not stack:\n                    stack.append(i)\n                else:\n                    res = max(res, i - stack[-1])\n        return res\nif __name__ == '__main__':\n    s = '))())(()'\n    print(Solution().longestValidParentheses(s))\n<\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u62ec\u53f7\u5339\u914d\u9996\u5148\u5c31\u662f\u7528\u6808\uff0c\u53ea\u8981\u7528\u6808\u8bb0\u5f55\u8fde\u7eed\u51fa\u6808\u6b21\u6570\u5373\u53ef\u3002<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/longest-valid-par [&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":1142,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2832"}],"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=2832"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2832\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2832"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}