LeetCode: Container With Most Water
来源:互联网 发布:医院体检软件 编辑:程序博客网 时间:2024/06/05 12:35
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 start = 0, end = height.size()-1; int max = INT_MIN; while(start < end) { int cur = std::min(height[start], height[end]) * (end - start); max = std::max(max, cur); if(height[start] <= height[end]) start++; else end--; } return max; }};
Round 2:
class Solution {public: int maxArea(vector<int> &height) { int left = 0, right = height.size()-1; int max = INT_MIN; while(left < right) { max = std::max(max, (right-left) * std::min(height[left], height[right])); if(height[left] > height[right]) right--; else left++; } return max; }};
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
- 自己学驱动13——内存管理单元MMU(虚拟地址和物理地址)
- structs2+ajax+jquery异步上传带type=file的表单
- MongoDB基本语法详解
- Android:从SD卡/拍照选择图片并进行剪裁的方法
- ギフトって….
- LeetCode: Container With Most Water
- 从 Objective-C 里的 Alloc 和 AllocWithZone 谈起
- 设计模式之单例模式Singleton
- C++之“继承与派生”
- xcode 4 制作静态库详解
- Android学习:Could not find XXX.apk!异常解决
- Android 开发环境搭建
- unity3d移动平台性能优化(9):为了好一点的图形效果可以酌情做哪些,哪些必须避免。
- windows内核错误处理