LeetCode - Container With Most Water
2013-08-28 21:59
267 查看
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.
..., 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 area=0; if(height.empty()||height.size()<2){ return area; } int i=0,j=height.size()-1; while(i<j){ if(height[i]>height[j]){ area=max(area,(j-i)*height[j]); j--; }else{ area=max(area,(j-i)*height[i]); i++; } } return area; } };
相关文章推荐
- LeetCode Online Judge 题目C# 练习 - Container With Most Water
- leetcode(1)container-with-most-water
- 【LeetCode】011 Container With Most Water
- 【leetcode】Container With Most Water
- Container With Most Water (隔板如何蓄水) 【leetcode】
- LeetCode题解:Container With Most Water
- LeetCode (11)Container With Most Water
- leetcode-Container With Most Water
- Leetcode Container With Most Water
- Container With Most Water Leetcode Python Java
- Leetcode题解:11. Container With Most Water
- Leetcode100: Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode Solutions : Container With Most Water
- [LeetCode 11] 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