{"id":864,"date":"2025-08-10T01:53:14","date_gmt":"2025-08-09T17:53:14","guid":{"rendered":"https:\/\/www.guanhaobo.cn\/?p=864"},"modified":"2025-08-10T01:55:25","modified_gmt":"2025-08-09T17:55:25","slug":"leetcode-11-%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":"https:\/\/www.guanhaobo.cn\/?p=864","title":{"rendered":"LeetCode 11 &#8211; \u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668"},"content":{"rendered":"<h1>\u9898\u76ee\u63cf\u8ff0<\/h1>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 height \u3002\u6709 n \u6761\u5782\u7ebf\uff0c\u7b2c i \u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f (i, 0) \u548c (i, height[i]) \u3002<\/p>\n<p>\u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e0e x \u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002<\/p>\n<p>\u8fd4\u56de\u5bb9\u5668\u53ef\u4ee5\u50a8\u5b58\u7684\u6700\u5927\u6c34\u91cf\u3002<\/p>\n<p>\u8bf4\u660e\uff1a\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002<\/p>\n<h1>\u9898\u76ee\u5206\u6790<\/h1>\n<p>\u5bb9\u5668\u7684\u5bb9\u79ef\u7531\u5bbd\u548c\u9ad8\u4e24\u90e8\u5206\u7ec4\u6210\uff0c\u5bbd\u5ea6\u662f\u4e24\u6761\u7ebf\u6a2a\u5750\u6807\u7684\u5dee\uff0c\u9ad8\u5ea6\u662f\u4e24\u6761\u7ebf\u9ad8\u5ea6\u7684\u6700\u5c0f\u503c\u3002<br \/>\n\u5bfb\u627e\u6700\u5927\u6c34\u91cf\uff0c\u4e5f\u5c31\u662f\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u90fd\u8981\u5c3d\u53ef\u80fd\u7684\u5927\u3002\u5bf9\u4e8e\u9898\u76ee\u7ed9\u51fa\u7684\u6570\u636e\uff0c\u4e0d\u540c\u9ad8\u5ea6\u4e4b\u95f4\u5e76\u4e0d\u8fde\u7eed\uff0c\u800c\u5bbd\u5ea6\u662f\u8fde\u7eed\u7684\uff0c\u56e0\u6b64\u8003\u8651\u4ece\u5bbd\u5ea6\u5165\u624b\u3002<br \/>\n\u4f7f\u7528\u53cc\u6307\u9488\uff0cleft \u6307\u5411\u6570\u7ec4\u6700\u5de6\u8fb9\uff0cright \u6307\u5411\u6570\u7ec4\u6700\u53f3\u8fb9\uff0c\u6b64\u65f6\u5bbd\u5ea6\u662f\u6700\u5927\u7684\u3002<br \/>\n&#8211; \u79fb\u52a8\u9ad8\u5ea6\u8f83\u5c0f\u7684\u6307\u9488\uff1a\u65b0\u7684\u5bb9\u79ef\u53ef\u80fd\u4f1a\u53d8\u5927\uff0c\u4e5f\u53ef\u80fd\u4f1a\u53d8\u5c0f<br \/>\n&#8211; \u79fb\u52a8\u9ad8\u5ea6\u8f83\u5927\u7684\u6307\u9488\uff1a\u65e0\u8bba\u79fb\u52a8\u591a\u5c11\u6b21\uff0c\u65b0\u7684\u5bb9\u79ef\u90fd\u4e0d\u53ef\u80fd\u53d8\u5927<\/p>\n<p>\u56e0\u6b64\u5bf9\u4e8e\u6b64\u523b\u9ad8\u5ea6\u8f83\u5c0f\u7684\u7ebf\uff0c\u540e\u7eed\u90fd\u6ca1\u5fc5\u8981\u4f5c\u4e3a\u8fb9\u754c\u4e86\uff0c\u53ef\u4ee5\u628a\u5b83\u5220\u9664\u4e86\uff0c\u76f8\u90bb\u7684\u7ebf\u6210\u4e3a\u65b0\u7684\u8fb9\u754c\uff08\u7531\u4e8e\u539f\u6765\u7684\u7ebf\u662f\u6570\u7ec4\u7684\u6700\u5de6\u4fa7\u6216\u6700\u53f3\u4fa7\uff0c\u56e0\u6b64\u53ea\u6709\u4e00\u4e2a\u76f8\u90bb\u7684\u7ebf\uff09\u3002<br \/>\n\u4f53\u73b0\u5728\u4ee3\u7801\u4e0a\u5c31\u662f\u6bcf\u6b21\u79fb\u52a8\u9ad8\u5ea6\u8f83\u5c0f\u7684\u6307\u9488\uff0c\u4e14\u6307\u9488\u53ea\u5141\u8bb8\u5411\u5185\u79fb\u52a8\u3002\u5982\u679c\u4e24\u4e2a\u6307\u9488\u9ad8\u5ea6\u76f8\u540c\uff0c\u5219\u79fb\u52a8\u54ea\u4e2a\u90fd\u4e00\u6837\u3002<\/p>\n<h1>Java<\/h1>\n<pre><code class=\"language-java line-numbers\">public int maxArea(int[] height) {\n    int left = 0;\n    int right = height.length - 1;\n    int ans = 0;\n    while (left &lt; right) {\n        int w = right - left;\n        int h = Math.min(height[left], height[right]);\n        int size = w * h;\n        ans = Math.max(ans, size);\n        if (height[left] &lt; height[right]) {\n            left++;\n        } else {\n            right--;\n        }\n    }\n    return ans;\n}\n<\/code><\/pre>\n<h1>Kotlin<\/h1>\n<pre><code class=\"language-kotlin line-numbers\">fun maxArea(height: IntArray): Int {\n    var left = 0\n    var right = height.size - 1\n    var ans = 0\n    while (left &lt; right) {\n        val size = min(height[left], height[right]) * (right - left)\n        ans = max(ans, size)\n        if (height[left] &lt; height[right]) {\n            left++\n        } else {\n            right--\n        }\n    }\n    return ans\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 height \u3002\u6709 n \u6761\u5782\u7ebf\uff0c\u7b2c i \u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f (i, 0 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[75,73,62],"class_list":["post-864","post","type-post","status-publish","format-standard","hentry","category-algo","tag-75","tag-73","tag-62"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=864"}],"version-history":[{"count":2,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/864\/revisions"}],"predecessor-version":[{"id":866,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/864\/revisions\/866"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}