It took me quite some time to finally optimize my solution from 21ms to 3ms :(

If you have difficulty understanding the following code, check this link for a detailed explanation.

```
public int maxArea(int[] height) {
int L = height.length, lo = 0, hi = L-1;
int max = 0;
while(lo<hi) {
int loMax = height[lo], hiMax = height[hi];
int candidate = (hi-lo) * (loMax<hiMax ? loMax : hiMax);
max = candidate > max ? candidate : max;
if(height[lo]<=height[hi])
while(lo<hi && height[lo]<=loMax) ++lo;
else
while(hi>lo && height[hi]<=hiMax) --hi;
}
return max;
}
```