- Question Description
- My Key
package LeetCode;
public class Test {
public static void main(String[] args) {
int[] num = {1,8,6,2,5,4,8,3,7};
System.out.println(maxArea(num));
}
public static int maxArea(int[] height) {
int rev = 0;
int i = 0;
int j = height.length-1;
int low = 0;
int high = 0;
while (i < j) {
if (height[i] < height[j]) {
low = height[i];
high = height[j];
i++;
} else {
high = height[i];
low = height[j];
j--;
}
rev = (rev > low*(j-i+1))? rev:(low*(j-i+1));
}
return rev;
}
}