Leetcode - 11 Container With Most Water (Medium)
題目描述:找出兩條線,使得構成的容器能夠容納最多的水。
public int maxArea(int[] height) {
int max = 0, i = 0, j = height.length - 1;
while (i < j) {
max = Math.max(max, (j - i) * Math.min(height[i], height[j]));
if (height[i] < height[j]) {
i++;
} else {
j--;
}
}
return max;
}