public class Solution {
public int maxArea(int[] height) {
int left = 0, right = height.length - 1;
int max = 0;
while (left <= right) {
max = Math.max(max, getMaxArea(left, right, height));
if (height[left] <= height[right]) {
left++;
} else {
right--;
}
}
return max;
}
private int getMaxArea(int left, int right, int[] height) {
int max = (right - left) * Math.min(height[left], height[right]);
return max;
}
}