public class Solution { public int maxArea(int[] height) { int maxa = 0; int maxi = 0; if(height.length<2) return 0; for(int i=0;i<height.length-1;i++){ if(height[i]<height[maxi]){ continue; } for(int j=height.length-1;j>i;j--){ if(height[j]>height[i]){ int maxmid = (j-i)*height[i]; maxa = maxa>maxmid?maxa:maxmid; break; } else{ int maxmid = (j-i)*height[j]; maxa = maxa>maxmid?maxa:maxmid; } } maxi = i; } return maxa; } }
时间: 2024-11-18 22:28:29