Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 537 Bytes

011.md

File metadata and controls

22 lines (20 loc) · 537 Bytes

11. Container With Most Water

Solution 1 (O(n))

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