{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "e53e28eea076409c9f0bf72a7cf601f2",
  "keywords": "贪心,数组,双指针",
  "title": "盛最多水的容器",
  "desc": [
    {
      "content": "\n<p>给你 <code>n</code> 个非负整数 <code>a<sub>1</sub>，a<sub>2，</sub>...，a</code><sub><code>n</code>，</sub>每个数代表坐标中的一个点 <code>(i, a<sub>i</sub>)</code> 。在坐标内画 <code>n</code> 条垂直线，垂直线 <code>i</code> 的两个端点分别为 <code>(i, a<sub>i</sub>)</code> 和 <code>(i, 0)</code> 。找出其中的两条线，使得它们与 <code>x</code> 轴共同构成的容器可以容纳最多的水。</p><p><strong>说明：</strong>你不能倾斜容器。</p><p> </p><p><strong>示例 1：</strong></p><p><img alt=\"\" src=\"https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0011.Container%20With%20Most%20Water/images/question_11.jpg\" style=\"height: 287px; width: 600px;\" /></p><pre><strong>输入：</strong>[1,8,6,2,5,4,8,3,7]<strong><br />输出：</strong>49 <strong><br />解释：</strong>图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下，容器能够容纳水（表示为蓝色部分）的最大值为 49。</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>height = [1,1]<strong><br />输出：</strong>1</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>height = [4,3,2,1,4]<strong><br />输出：</strong>16</pre><p><strong>示例 4：</strong></p><pre><strong>输入：</strong>height = [1,2,1]<strong><br />输出：</strong>2</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>n = height.length</code></li>\t<li><code>2 <= n <= 3 * 10<sup>4</sup></code></li>\t<li><code>0 <= height[i] <= 3 * 10<sup>4</sup></code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic int maxArea(int[] height) {\n\t\tint N = height.length;\n\t\tint i = 0;\n\t\tint j = N - 1;\n\t\tint max = 0;\n\t\twhile (i < j) {\n\t\t\tint c = (j - i) * Math.min(height[i], height[j]);\n\t\t\tif (c > max) {\n\t\t\t\tmax = c;\n\t\t\t}\n\t\t\tif (height[i] > height[j]) {\n\t\t\t\tj--;\n\t\t\t} else {\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\treturn max;\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-b087bfd39b6949ab8e67326033d74792",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469816"
}