class Solution {
public int maxArea(int[] height) {
int max = 0;
for(int i=0; i<height.length; i++){
for(int j=i+1; j<height.length; j++){
max = Math.max(max,(j-i)*Math.min(height[i],height[j]));
}
}
return max;
}
}
暴力+优化
class Solution {
public int maxArea(int[] height) {
int low = 0, high = height.length-1, max = 0;
while(low<high){
max = Math.max((high-low)*Math.min(height[low],height[high]),max);
if(height[low]>height[high]){
int t = height[high];
while(low<high&&height[high]<=t)
high--;
}else{
int t = height[low];
while(low<high&&height[low]<=t)
low++;
}
}
return max;
}
}