class Solution {
public int maxArea(int[] height) {
int left = 0;
int right = height.length - 1;
int maxArea = 0;
while (left < right) {
int currentHeight = Math.min(height[left], height[right]);
int currentWidth = right - left;
int currentArea = currentHeight * currentWidth;
maxArea = Math.max(maxArea, currentArea);
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return maxArea;
}
}
Open to updates and suggestions.
Top comments (0)