{"id":2779,"date":"2020-01-16T13:23:10","date_gmt":"2020-01-16T05:23:10","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2779"},"modified":"2020-01-16T13:23:10","modified_gmt":"2020-01-16T05:23:10","slug":"%e3%80%90leetcode%e3%80%910011-%e7%9b%9b%e6%9c%80%e5%a4%9a%e6%b0%b4%e7%9a%84%e5%ae%b9%e5%99%a8","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/algorithm\/2779\/","title":{"rendered":"\u3010LeetCode\u30110011 \u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode-cn.com\/problems\/container-with-most-water\">https:\/\/leetcode-cn.com\/problems\/container-with-most-water<\/a><\/p>\n\n\n<p>\u4ee3\u7801\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-<br \/><br \/>class Solution(object):<br \/>    def maxArea(self, height):<br \/>        <em>\"\"\"<br \/><\/em><em>        <\/em><strong><em>:type<\/em><\/strong><em> height: List[int]<br \/><\/em><em>        <\/em><strong><em>:rtype<\/em><\/strong><em>: int<br \/><\/em><em>        \"\"\"<br \/><\/em><em>        <\/em>weights = [[0 for _ in range(len(height))] for _ in range(len(height))]<br \/>        for i in range(1, len(weights)):<br \/>            for j in range(len(weights) - i):<br \/>                for k in range(j, j + i):<br \/>                    if min(height[j], height[j + i]) * i &lt; max(weights[j][k], weights[k][j + i]):<br \/>                        weights[j][j + i] = max(weights[j][k], weights[k][j + i])<br \/>                    else:<br \/>                        weights[j][j + i] = min(height[j], height[j + i]) * i<br \/>        return max(max(row) for row in weights)<br \/>    <br \/>    <br \/><br \/><br \/>if __name__ == '__main__':<br \/>    height = [1, 8, 6, 2, 5, 4, 8, 3, 7]<br \/>    print(Solution().maxArea(height))<br \/><\/pre>\n\n\n<p><strong>\u601d\u8def<\/strong>\uff1a\u8fd9\u9053\u9898\u4e0a\u9762\u7684\u4ee3\u7801\u5e76\u4e0d\u80fd\u5b8c\u5168AC\uff08\u4f1a\u8d85\u65f6\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u7ed3\u679c\u662f\u5bf9\u7684\uff09\uff0c\u4f46\u662f\u8d34\u51fa\u6765\u662f\u56e0\u4e3a\u8fd9\u9519\u8bef\u592a\u7ecf\u5178\u4e862333\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"442\" src=\"\/wp-content\/uploads\/2020\/01\/\u56fe\u7247-47.png\" alt=\"\" class=\"wp-image-2780\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/01\/\u56fe\u7247-47.png 628w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/01\/\u56fe\u7247-47-300x211.png 300w\" sizes=\"(max-width: 628px) 100vw, 628px\" \/><\/figure><\/div>\n\n\n<p>\u8fd9\u9053\u9898\uff08\u6211\uff09\u91c7\u7528\u4e86\u52a8\u6001\u89c4\u5212\u7684\u601d\u60f3\uff0c\u5148\u662f\u89e3\u51b3\u4e00\u4e2a\u957f\u5ea6\u7684\uff0c\u518d\u627e\u4e24\u4e2a\u957f\u5ea6\u7684\u6700\u4f18\u89e3\u518d\u627e\u4e09\u4e2a\u7684\u4ee5\u6b64\u7c7b\u63a8\uff0c\u8fd9\u6837\u8981\u7528\u5230\u4e09\u5c42\u5faa\u73af\uff0c\u5e94\u8be5\u662fn^3\uff0c\u4f46\u662f\u8fd9\u6837\u867d\u7136\u627e\u51fa\u4e86\u7ed3\u679c\uff0c\u4f46\u662f\u4f1a\u8d85\u65f6\uff0c\u56e0\u4e3a\u4ee3\u4ef7\u592a\u5927\u4e86\uff0c\u5bf9\u4e8e\u8fd9\u9053\u9898\uff0c\u66b4\u529b\u4e5f\u65e0\u975e\u662fn^2\uff0c\u8fd9\u4e0d\u7981\u8ba9\u6211\u9677\u5165\u4e86\u6c89\u601d\u3002<\/p>\n\n\n<p>\u540e\u6765\u6211\u60f3\u660e\u767d\u4e86\uff0c\u5e76\u4e0d\u662f\u4ec0\u4e48\u90fd\u53ef\u4ee5\u7528\u52a8\u6001\u89c4\u5212\u4ee5\u8fbe\u5230\u6700\u597d\u7684\u6548\u679c\uff0c\u8fd9\u9053\u9898\u4f7f\u7528\u5de6\u53f3\u6307\u9488\u5411\u91cc\u79fb\u52a8\uff08\u6bcf\u6b21\u79fb\u52a8\u8f83\u5c0f\u7684\u4e00\u8fb9\uff09\uff0c\u662f\u6700\u597d\u7684\u89e3\u6cd5\uff0c\u56e0\u4e3a\u79fb\u52a8\u8f83\u5c0f\u7684\u4e00\u8fb9\u8bf4\u660e\u5f53\u524d\u5bb9\u5668\u5982\u679c\u8981\u6269\u5927\uff0c\u4e00\u5b9a\u662f\u8f83\u5c0f\u7684\u4e00\u8fb9\u662f\u77ed\u677f\uff08\u6728\u6876\u539f\u7406\uff0c\u5bf9\u5427\uff09\u8fd9\u6837\u4e00\u76f4\u8bb0\u5f55\u6700\u5927\u503c\u3002<\/p>\n\n\n<p>\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u8fd9\u9053\u9898\u66b4\u529b\u590d\u6742\u5ea6\u751a\u81f3\u4f18\u4e8e\u52a8\u5f52\uff0c\u539f\u56e0\u5c31\u662f\u8fd9\u9053\u9898<strong>\u5e76\u4e0d\u5b58\u5728\u591a\u4e2a\u5b50\u7ed3\u6784\u7684\u96c6\u5408\u4f18\u4e8e\u5168\u5c40<\/strong>\u3002\u56e0\u6b64\u52a8\u5f52\u76f8\u5f53\u4e8e\u591a\u7b97\u4e86\u597d\u591a\u65e0\u7528\u529f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/leetcode-cn.com\/problems\/container-with-mo [&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":1394,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2779"}],"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=2779"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2779\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2779"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}