> For the complete documentation index, see [llms.txt](https://r24zeng.gitbook.io/leetcode-notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://r24zeng.gitbook.io/leetcode-notebook/zhong-yu-shua-dao-100-dao-le-wo-shi-fen-shui-ling/bu-chong-120-dao/11.-container-with-most-water.md).

# 11. Container With Most Water

\# Medium

{% hint style="info" %}
Two pointers.

Left pointer and right pointer to make sliding window. Keep maximum `area` in record, and move left or right pointer to ensure both of them are the longest vertical lines, compute the temporary area to be `temp`.
{% endhint %}

### Solution

1. Keep maxium area in record.
2. Move left or right pointer each time by finding the longest two lines.

简单来说，有两种可能性能找到最大值，第一种距离尽量最远的两个垂线，第二种高度尽量最高的两条垂线。

{% tabs %}
{% tab title="Python" %}

```python
class Solution(object):
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        start = 0
        end = len(height) - 1
        area = 0
        while start < end:
            temp = min(height[start], height[end]) * (end-start)
            area = max(area, temp)
            if height[start] < height[end]:
                start += 1
            else:
                end -= 1
                
        return area
```

{% endtab %}
{% endtabs %}

Time complexity = $$O(n)$$ , space complexity = $$O(1)$$&#x20;
