{"id":231,"date":"2024-11-30T10:25:22","date_gmt":"2024-11-30T02:25:22","guid":{"rendered":"http:\/\/getzs.online\/?p=231"},"modified":"2024-11-30T10:34:32","modified_gmt":"2024-11-30T02:34:32","slug":"leetcode-hot-100-6","status":"publish","type":"post","link":"https:\/\/hello.getzs.online\/index.php\/2024\/11\/30\/leetcode-hot-100-6\/","title":{"rendered":"LeetCode Hot100 -6"},"content":{"rendered":"\n<p><a href=\"https:\/\/leetcode.cn\/problems\/container-with-most-water\/description\/?envType=study-plan-v2&amp;envId=top-100-liked\">11. \u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668<\/a><\/p>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;<code>n<\/code>&nbsp;\u7684\u6574\u6570\u6570\u7ec4&nbsp;<code>height<\/code>&nbsp;\u3002\u6709&nbsp;<code>n<\/code>&nbsp;\u6761\u5782\u7ebf\uff0c\u7b2c&nbsp;<code>i<\/code>&nbsp;\u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f&nbsp;<code>(i, 0)<\/code>&nbsp;\u548c&nbsp;<code>(i, height[i])<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf\uff0c\u4f7f\u5f97\u5b83\u4eec\u4e0e&nbsp;<code>x<\/code>&nbsp;\u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u5bb9\u5668\u53ef\u4ee5\u50a8\u5b58\u7684\u6700\u5927\u6c34\u91cf\u3002<\/p>\n\n\n\n<p><strong>\u8bf4\u660e\uff1a<\/strong>\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"801\" height=\"383\" src=\"http:\/\/hello.getzs.online\/wp-content\/uploads\/2024\/11\/image.png\" alt=\"\" class=\"wp-image-232\" srcset=\"https:\/\/hello.getzs.online\/wp-content\/uploads\/2024\/11\/image.png 801w, https:\/\/hello.getzs.online\/wp-content\/uploads\/2024\/11\/image-300x143.png 300w, https:\/\/hello.getzs.online\/wp-content\/uploads\/2024\/11\/image-768x367.png 768w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>[1,8,6,2,5,4,8,3,7]\n<strong>\u8f93\u51fa\uff1a<\/strong>49 \n<strong>\u89e3\u91ca\uff1a<\/strong>\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93\u5165\u6570\u7ec4 [1,8,6,2,5,4,8,3,7]\u3002\u5728\u6b64\u60c5\u51b5\u4e0b\uff0c\u5bb9\u5668\u80fd\u591f\u5bb9\u7eb3\u6c34\uff08\u8868\u793a\u4e3a\u84dd\u8272\u90e8\u5206\uff09\u7684\u6700\u5927\u503c\u4e3a&nbsp;49\u3002<\/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>height = [1,1]<br><strong>\u8f93\u51fa\uff1a<\/strong>1<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>n == height.length<\/code><\/li>\n\n\n\n<li><code>2 &lt;= n &lt;= 10<sup>5<\/sup><\/code><\/li>\n\n\n\n<li><code>0 &lt;= height[i] &lt;= 10<sup>4<\/sup><\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c4\u505a\u6cd5\uff1a<\/h2>\n\n\n\n<p>\u901a\u8fc7\u4e24\u5c42\u5faa\u73af\u679a\u4e3e\uff0c\u627e\u51fa\u6240\u6709\u53ef\u80fd\u6027\uff0c\u5f97\u51fa\u6700\u5927\u9762\u79ef\u3002\u590d\u6742\u5ea6O(n<sup>2<\/sup>)\uff0c10<sup>5*2<\/sup>\u8d85\u51fa\u65f6\u9650\u8981\u6c42\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tpublic int maxArea(int&#91;] height) {\n\t\tint n = height.length;\n\t\tint mx = 0;\n\t\tfor (int i = 0 ; i &lt; n ; i++) {\n\t\t\tfor (int j = i + 1 ; j &lt; n ; j++) {\n\t\t\t\tmx = Math.max(mx, Math.min(height&#91;i], height&#91;j]) * (j - i));\n\t\t\t}\n\t\t}\n\t\treturn mx;\n\t}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u53cc\u6307\u9488\u505a\u6cd5\uff1a<\/h2>\n\n\n\n<p>\u901a\u8fc7\u53cc\u6307\u9488\u7684\u6ed1\u52a8\uff0c\u5f53\u5927\u8fb9\u4fdd\u6301\u4e0d\u52a8\u65f6\uff0c\u8ba9\u5c0f\u8fb9\u53d8\u5927\uff0c\u4f1a\u4f7f\u6574\u4e2a\u9762\u79ef\u603b\u4f53\u53d8\u5927\u3002\u590d\u6742\u5ea6O(n)\u3002<\/p>\n\n\n\n<p>\u6ce8\uff1a\u539f\u7406\u662f\uff0c\u5982\u679c\u4e0d\u6539\u53d8\u5c0f\u8fb9\u7684\u9ad8\u5ea6\uff0c\u90a3\u4e48\u603b\u4f53\u9762\u79ef\u4e0d\u4f1a\u8d85\u51fax*t\uff0c\u4e0d\u5982\u53bb\u5c1d\u8bd5\u6539\u53d8\u5c0f\u8fb9\u3002\u5373\u77ed\u677f\u6548\u5e94\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tpublic int maxArea(int&#91;] height) {\n\t\tint n = height.length;\n\t\tint i = 0, j = n - 1;\n\t\tint mx = 0;\n\t\twhile (i &lt; j) {\n\t\t\tmx = Math.max(mx, Math.min(height&#91;i], height&#91;j]) * (j - i));\n\t\t\tif (height&#91;i] &lt; height&#91;j]) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tj--;\n\t\t\t}\n\t\t}\n\t\treturn mx;\n\t}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>11. \u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a&nbsp;n&nbsp;\u7684\u6574\u6570\u6570\u7ec4&nbsp;height&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[3],"class_list":["post-231","post","type-post","status-publish","format-standard","hentry","category-leetcode","tag-leetcode-hot100"],"_links":{"self":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts\/231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":2,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":239,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/posts\/231\/revisions\/239"}],"wp:attachment":[{"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hello.getzs.online\/index.php\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}