leetcode-Container With Most Water
来源:互联网 发布:vb for循环教学设计 编辑:程序博客网 时间:2024/05/30 12:30
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.
class Solution {public: int maxArea(vector<int> &height) { int len = height.size(); int i = 0, j = len -1; int sum = 0; int k; while(i<j) { sum = max(sum,min(height[i],height[j])*(j-i)); if(height[i]<height[j]) { k = i; while(k<j&&height[k]<=height[i])k++; i = k; } else { k = j; while(k>i&&height[k]<=height[j])k--; j = k; } } return sum; }};
0 0
- LeetCode: Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode Container With Most Water
- LeetCode: Container With Most Water
- [Leetcode] Container With Most Water
- Leetcode: Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode Container With Most Water
- [Leetcode] Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode-Container With Most Water
- Container With Most Water leetcode
- LeetCode - Container With Most Water
- LeetCode: Container With Most Water
- Leetcode: Container With Most Water
- 【LeetCode】Container With Most Water
- Leetcode: Container With Most Water
- LeetCode:Container With Most Water
- 蝉知门户系统迁移到SAE平台-浏览目录空间
- 汉诺塔系列问题: 汉诺塔II、汉诺塔III、汉诺塔IV、汉诺塔V、汉诺塔VI、汉诺塔VII
- 【剑指offer】Q9:斐波那契数列
- Scrapy 安装
- 饭卡
- leetcode-Container With Most Water
- 机器学习之KNN算法
- Tomcat 启动 远程调试
- 主要几个LTE类的默认参数设置
- VS2010开发环境之使用技巧
- Linux学习笔记——例说makefile 索引博文
- 《狂斩三国》游戏破解
- 20140705:c++builder去掉窗体的关闭按钮
- IOS7 文件和文件夹的管理