java.lang.Object
g0001_0100.s0011_container_with_most_water.Solution

public class Solution extends Object
11 - Container With Most Water.<p>Medium</p> <p>Given <code>n</code> non-negative integers <code>a<sub>1</sub>, a<sub>2</sub>, &hellip;, a<sub>n</sub></code> , where each represents a point at coordinate <code>(i, a<sub>i</sub>)</code>. <code>n</code> vertical lines are drawn such that the two endpoints of the line <code>i</code> is at <code>(i, a<sub>i</sub>)</code> and <code>(i, 0)</code>. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.</p> <p><strong>Notice</strong> that you may not slant the container.</p> <p><strong>Example 1:</strong></p> <p><img src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg" alt="" /></p> <p><strong>Input:</strong> height = [1,8,6,2,5,4,8,3,7]</p> <p><strong>Output:</strong> 49</p> <p><strong>Explanation:</strong> The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> height = [1,1]</p> <p><strong>Output:</strong> 1</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> height = [4,3,2,1,4]</p> <p><strong>Output:</strong> 16</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> height = [1,2,1]</p> <p><strong>Output:</strong> 2</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == height.length</code></li> <li><code>2 <= n <= 10<sup>5</sup></code></li> <li><code>0 <= height[i] <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxArea

      public int maxArea(int[] height)