Here is my code for this problem, and is O(n).

int maxArea(int height[], int n) {

int ret = 0;

int area = 0;

```
int i = 0 ;
int j = n - 1;
while(i < j) {
if(height[i] < height[j]) {
area = height[i] * (j - i);
} else {
area = height[j] * (j - i);
}
ret = ret > area ? ret : area;
if(height[i] < height[j]) i++;
else j--;
}
return ret;
```

}

but, I have a question: if height[i] == height[j] , and we will go to j-- , but if height[++i] > height[--j] , then the right way is i++, how to slove this problem?