1public int maxArea(int[] heights) {
2 int left = 0;
3 int right = heights.length - 1;
4 int maxArea = 0;
5
6 while (left < right) {
7 int width = right - left;
8 int height = Math.min(heights[left], heights[right]);
9 int currentArea = width * height;
10 maxArea = Math.max(maxArea, currentArea);
11
12 if (heights[left] < heights[right]) {
13 left++;
14 } else {
15 right--;
16 }
17 }
18
19 return maxArea;
20}