```
public class Solution {
public int maxArea(int[] height) {
int max = 0;
int i = 0;
int j = height.length - 1;
while(i < j){
int area = Math.min(height[i], height[j]) * (j - i);
max = Math.max(max, area);
if(height[i] < height[j]){
int p = i + 1;
while(p < j && height[i] >= height[p]){
p++;
}
i = p;
}else{
int p = j - 1;
while(i < p && height[j] >= height[p]){
p--;
}
j = p;
}
}
return max;
}
}
```