1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class Solution { public int maxArea(int[] height) {
int maxArea = 0; int i = 0, j = height.length - 1; while (i < j) { maxArea = Math.max(maxArea, Math.min(height[i], height[j]) * (j - i)); if (height[i] < height[j]) { i++; } else { j--; } }
return maxArea; } }
|
References
11. Container With Most Water