Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a contain…
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a contain…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:盛水,容器,题解,leetcode, 力扣,python, c++, java 目录 题目描述 题目大意 解题方法 双指针 日期 题目地址:https://leetcode.com/problems/container-with-most-water/description/ 题目描述 Given n non-negative integers a1,…
给定 n 个非负整数 a1,a2,…,an,每个数代表坐标中的一个点 (i, ai) .画 n 条垂直线,使得垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水. 详见:https://leetcode.com/problems/container-with-most-water/description/ 实现语言:Java 方法一:暴力解,超时 class Solution { public int maxArea…
给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水. 说明:你不能倾斜容器,且 n 的值至少为 2. 示例: 输入: [1,8,6,2,5,4,8,3,7] 输出: 49 方法一:暴力法 class Solution { public: int maxArea(vector<int>& he…
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a containe…
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a containe…
LeetCode:盛最多水的容器[11] 题目描述 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水. 说明:你不能倾斜容器,且 n 的值至少为 2. 图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7].在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49. 示例: 输入: [1…
11. 盛最多水的容器 给定 n 个非负整数 a1,a2,-,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水. 说明:你不能倾斜容器,且 n 的值至少为 2. 图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7].在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49. 示例: 输入: [1,8,6,2,5,4,8,3,7…
盛最多水的容器 给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) .在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0).找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水. 看起来遍历求面积就可以了 first submission class Solution: def maxArea(self, height): """ :type height: List[int] :rtyp…