class Solution {
public int maxArea(int[] height) {
int max_area=0;
for(int i=0; i<height.length; i++){
for(int j=i+1; j<height.length; j++){
int x = j-i;
int y = height[i]<height[j]?height[i]:height[j];
int area = x*y;
max_area = max_area>area?max_area:area;
}
}
return max_area;
}
}
class Solution {
public int maxArea(int[] height) {
int left=0, right=height.length-1;
int max_area=0;
while(left<right){
int area = (right-left) * Math.min(height[left],height[right]);
max_area = Math.max(max_area,area);
// 保存值较大的边
if (height[left]>height[right]){
right--;
}
else{
left++;
}
}
return max_area;
}
}