![]()
![]()
package my;
public class MaxAreaSolution {
public int maxArea(int[] height){
if(height.length <1){
return 0;
}
int max = 0;
int current =0;
for(int i= 0 ; i< height.length-1; i++){
for(int j=i+1; j<height.length; j++){
if(height[i] < height[j]){
current = height[i] * Math.abs(j-i) ;
max = Math.max(max, current);
} else{
current = height[j] * Math.abs(j-i) ;
max = Math.max(max ,current);
}
}
}
return max;
}
public static void main(String [] args){
int[] n = {1, 8, 6, 2, 5, 4, 8, 3, 7};
MaxAreaSolution area = new MaxAreaSolution();
int maxArea = area.maxArea(n);
System.out.println(maxArea);
}
}