mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2025-12-06 12:54:07 +00:00
22 lines
418 B
C++
22 lines
418 B
C++
#include "soln.hpp"
|
|
|
|
int Solution::maxArea(vector<int> &height)
|
|
{
|
|
int left = 0, right = height.size() - 1;
|
|
int max_water = 0;
|
|
while (left != right)
|
|
{
|
|
max_water = max(max_water, min(height[left], height[right]) * (right - left));
|
|
if (height[left] > height[right])
|
|
right--;
|
|
else
|
|
left++;
|
|
}
|
|
return max_water;
|
|
}
|
|
|
|
bool Solution::test(vector<int> &height, int answer)
|
|
{
|
|
return maxArea(height) == answer;
|
|
}
|