LeetCode 11. Container With Most Water(盛最多的水)
来源:互联网 发布:手机图片涂鸦软件 编辑:程序博客网 时间:2024/05/20 06:53
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 Container, such that the container contains the most water.
题目大意:
数组中的每个数对应一条线段的长度,索引对应x坐标,两个索引可以组成一个底部的宽,高度就是前面所说的线段的长度,而既然是要盛水,高度就是对应索引两个线段中较短的一个。
AC代码:
int maxArea(vector<int>& height) {
int i = 0;
int j = height.size() - 1;
int ret = 0;
while(i < j)
{
int area = (j - i) * min(height[i], height[j]);
ret = max(ret, area);
if (height[i] <= height[j])
i++;
else
j--;
}
return ret;
}
- LeetCode | Container with most water(装最多的水)
- LeetCode 11. Container With Most Water(盛最多的水)
- Leetcode刷题记——11. Container With Most Water(装最多水的容器)
- Container With Most Water 盛最多的水
- Container With Most Water (容器中盛最多的水)
- LeetCode OJ 之 Container With Most Water(能装最多水的容器)
- 11. Container With Most Water(求能装最多水的容器)
- (Leetcode)11. Container With Most Water
- Container With Most Water 装最多的水
- Container With Most Water(能装最多水的容器)
- 含水最多的容器(Container With Most Water)
- Container With Most Water "最多盛水问题"
- Container With Most Water 求容器里能放最多的水 @LeetCode
- LeetCode 11. Container With Most Water(容器装水)
- Container With Most Water --装最多水的容器(重)
- 383.Container With Most Water-装最多水的容器(中等题)
- 383.Container With Most Water-装最多水的容器(中等题)
- 6.container-with-most-water(装最多水的容器)
- 使用callable获取子线程的返回值
- dp小总结
- Hadoop小文件存取解决方案
- 直接内存DirectBuffer
- JAVA 用法陷阱(suitable for 中级JAVA开发工程师)
- LeetCode 11. Container With Most Water(盛最多的水)
- 暑期学习 LSTM 笔记
- 使用spring @Scheduled注解执行定时任务
- 一起Talk Android吧(第三十七回:Android中的Fragment二)
- 编译apache出现的问题:configure: error: APR not found . Please read the documentation
- 使用IntelliJ IDEA实现Spring HelloWorld
- 傅里叶的开篇
- BZOJ 4318: OSU! 期望dp
- android自定义控件-----自定义数字价格键盘