題目比較簡單,每次找較小的板往裏移,得到的容器的容積最大的就是所求的容積
public class Solution {
public static int maxArea(int[] height) {
int begin = 0, high, end = height.length - 1;
int max = 0;
while (end >= begin) {
high = height[begin] < height[end] ? height[begin] : height[end];
max = high * (end - begin) > max ? high * (end - begin) : max;
if (height[begin] < height[end])
begin++;
else
end--;
}
return max;
}
}