Container With Most Water
来源:互联网 发布:最精准的足彩数据分析 编辑:程序博客网 时间:2024/06/06 13:55
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.
Note: You may not slant the container and n is at least 2.
class Solution {
public:int maxArea(vector<int>& height) {
vector<int> v = height;
int begin = 0;
int end = v.size() - 1;
int max = 0;
int temp = 0;
max = (end - begin) * lower(v[begin],v[end]);
while(begin < end){
temp = (end - begin) * lower(v[begin],v[end]);
max = max > temp?max:temp;
if(v[begin] > v[end]) end--;
else begin++;
}
return max;
}
int lower(int a,int b){
return a > b ? b : a;
}
};
阅读全文
0 0
- Container With Most Water
- Container with most water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- Container With Most Water
- 第四周 【项目4
- keras学习笔记-二(Sequential 模型)
- java---TestThraed(2)
- 20170927_二分查找
- 欢迎使用CSDN-markdown编辑器
- Container With Most Water
- 【转】在Android中使用adb命令时关于权限方面的一些总结
- 【51Nod1689】逛街
- Feng Shui POJ
- java---TestThread(3)
- 加帕里的聚会 树链剖分 + 线段树(区间加 、区间赋值)
- react native学习笔记11——react-native-swiper轮播图
- qbxt集训cogs2682. 膜拜
- 增强版插入排序--二分的结合