Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxArea(vector<int>& height) {
- int left, right, ans;
- left = 0; right = height.size()-1; ans = 0;
- while(left < right){
- int h = min(height[left], height[right]);
- ans = max(ans, h*(right-left));
- while(height[left] <= h && left < right) left++;
- while(height[right] <= h && left < right) right--;
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment