nikunjsoni

11

Apr 13th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxArea(vector<int>& height) {
  4.         int left, right, ans;
  5.         left = 0; right = height.size()-1; ans = 0;
  6.        
  7.         while(left < right){
  8.             int h = min(height[left], height[right]);
  9.             ans = max(ans, h*(right-left));
  10.             while(height[left] <= h && left < right) left++;
  11.             while(height[right] <= h && left < right) right--;
  12.         }
  13.        
  14.         return ans;
  15.     }
  16. };
Advertisement
Add Comment
Please, Sign In to add comment