Leetcode: Container With Most Water
2013-01-14 12:40
295 查看
//use two pointers: move the shorter one until they meet in the middle class Solution { public: int maxArea(vector<int> &height) { // Start typing your C/C++ solution below // DO NOT write int main() function int size=height.size(); if(size<2) return -1; int i=0,j=size-1,temp=0,max=0; while(i<j){ temp=(j-i)*(height[i]<height[j]?height[i]:height[j]); max=max<temp?temp:max; if(height[i]<height[j]) while(height[i]>height[++i]); else while(height[j]>height[--j]); } return max; } };
相关文章推荐
- LeetCode 11 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 011 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
- LeetCode 之 Container With Most Water — C 实现
- LeetCode 11 Container With Most Water
- leetcode之11. Container With Most Water(C++解法)
- LeetCode-Container With Most Water
- Leetcode 11 Container With Most Water
- leetcode11 Container With Most Water
- 【LeetCode】011 Container With Most Water
- LeetCode 11---Container With Most Water
- LeetCode Container With Most Water
- leetcode(11) Container With Most Water