# Problem 11: Container With Most Water

> [https://leetcode.com/problems/container-with-most-water/](https://leetcode.com/problems/container-with-most-water/)

## 思路

## ![](https://1241747088-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lpv9LvBSlFaukf_ALqh%2F-Lpv9NPw3Ji1X5Vk8CES%2F-Lpv9ylm7b26RYdwhinW%2FcontainerWater.png?generation=1569729546254327\&alt=media)

```java
public class Solution {
    public int maxArea(int[] height) {
        int left = 0, right = height.length - 1;
        int max = 0;
        while (left <= right) {
            max = Math.max(max, getMaxArea(left, right, height));
            if (height[left] <= height[right]) {
                left++;
            } else {
                right--;
            }
         }

        return max;
    }

    private int getMaxArea(int left, int right, int[] height) {
        int max = (right - left) * Math.min(height[left], height[right]);
        return max;
    }
}
```

## 易错点

1. 什么时候求 max，什么时候求 min 要分清
