Created
June 22, 2024 19:50
-
-
Save SuryaPratapK/d676a530199642eddeba518cf120a880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int maxArea(vector<int>& height) { | |
int left=0, right=height.size()-1; | |
int max_area = 0; | |
int curr_area; | |
while(left < right) | |
{ | |
curr_area = (right-left)*min(height[left], height[right]); | |
max_area = max_area < curr_area ? curr_area: max_area; | |
height[left] > height[right] ? --right: ++left; | |
} | |
return max_area; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment