Container With Most Water
2015-01-05 09:01
267 查看
class Solution { public: int maxArea(vector<int> &height) { int res=0; int head=0; int tail=height.size()-1; res=(tail-head)*(height[head]>height[tail]?height[tail]:height[head]); while(head<tail) { if(height[head]<height[tail]) { int tmp=height[head]; while((head<tail)&&(height[head]<=tmp)) { head++; } tmp=(tail-head)*(height[head]>height[tail]?height[tail]:height[head]); if(tmp>res) { res=tmp; } } else { int tmp=height[tail]; while((head<tail)&&(height[tail]<=tmp)) { tail--; } tmp=(tail-head)*(height[head]>height[tail]?height[tail]:height[head]); if(tmp>res) { res=tmp; } } } return res; } };
相关文章推荐
- 【LeetCode】Container with Most Water
- Container With Most Water
- LeedCode Container With Most Water
- 11. Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode Container With Most Water
- [LeetCode]Container With Most Water
- 11. Container With Most Water
- Container With Most Water
- 11. Container With Most Water
- Leetcode-Container With Most Water
- Analysis on “Container With Most Water ”
- Container With Most Water
- Container With Most Water —— Leetcode
- Container With Most Water
- LeetCode 11_Container With Most Water
- leetcode第一刷_Container With Most Water
- LeetCode--Container With Most Water
- DAY6:leetcode #11 Container With Most Water
- [LeetCode] Container with most water