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