Title:
GivenNnon-negative integersa1 ,a2 , ...,an , where each represents a point at coordinate (I,ai ).NVertical lines is drawn such that the both endpoints of lineIis at (I,ai ) and (I, 0). Find lines, which together with X-axis forms a container, such that the container contains the most water.
Note:you may not slant the container.
Translation: All the numbers of an array are greater than 0, the height of a pair of planks, so that the most water loading. Short plate height of volume * length difference
Problem-solving ideas: From the beginning and end of the Traverse, and Maxwater flag current maximum water. If the front pointer refers to a small height, it is backward. If the latter refers to a small, then forward.
Because the water is up to the short plate height multiplied by the length difference. So before the hands and end of the hand meet, get the biggest water is the request. and the previous
Code:
public int Maxarea (int[] height) { int left = 0; int right = Height.length-1; int maxwater =-1; while (left < right) { int water = math.min (Height[left],height[right]) * (right-left); Maxwater = Math.max (maxwater,water); if (Height[left] < height[right]) left++; else right--; } return maxwater; }
Leetcode Container with the most water pack as much water as possible