Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.输入一个数组,数组的每个元素都表明了一条垂直的线,其中每个元素的位置表明横坐标,元素的值表明纵坐标。咱们须要找出这些线所围成的“容器”,能装最多水的水量。数组
public int maxArea(int[] height) { int maxArea = 0; int start = 0; int end = height.length-1; while(start < end){ maxArea = Math.max(maxArea, Math.min(height[start], height[end])*(end-start)); if(height[start] < height[end]) start ++; else end--; } return maxArea; }