C
int min(int num1, int num2)
{
if (num1 > num2)
{
return num2;
}
else
{
return num1;
}
}int maxArea(int* height, int heightSize){
int l, r, volume;
l = 0;
r = heightSize - 1;
volume = 0;
while (l < r)
{
int hei = min(height[l],height[r]);
int wide = r - l;
if (hei * wide > volume)
{
volume = hei * wide;
}
if (height[l] <= height[r])
{
l += 1;
}
else
{
r -= 1;
}
}
return volume;}
Python
class Solution:
def maxArea(self, height: List[int]) -> int:
l, r = 0, len(height) - 1
volume = 0
while l < r:
wei = min(height[l],height[r])
wide = r - l
if wei * wide > volume:
volume = wei * wide
if height[l] <= height[r]:
l += 1
else:
r -= 1
return volume