Advertisement
jayati

Container With Most Water

May 1st, 2024
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int maxArea(vector<int>& height) {
  4.         int mxArea=0;
  5.         int l=0;
  6.         int r=height.size()-1;
  7.         while(l<r)
  8.         {
  9.             mxArea = max(mxArea,(r-l)*min(height[r],height[l]));
  10.  
  11.             if(height[l]<height[r])
  12.             {
  13.                 l++;
  14.             }
  15.             else
  16.             {
  17.                 r--;
  18.             }
  19.         }
  20.         return mxArea;
  21.     }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement