solution.json 2.8 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "f46a96dc0f3243df927e534ab3659466",
  "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": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#define MAX(a, b) (((a) < (b)) ? (b) : (a))\n#define MIN(a, b) (((a) > (b)) ? (b) : (a))\nint maxArea(int *height, int heightSize)\n{\n\tint max = 0;\n\tint i = 0, j = heightSize - 1;\n\tint a;\n\twhile (i < j)\n\t{\n\t\ta = MIN(height[i], height[j]) * (j - i);\n\t\tmax = MAX(max, a);\n\t\tif (height[i] > height[j])\n\t\t\t--j;\n\t\telse\n\t\t\t++i;\n\t}\n\treturn max;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-14099290be73415196ac10c7668e7aaf",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600469816"
}