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.
Note: You may not slant the container.
想了很长时间,实际上处理的长方形的面积。假设横坐标长度为 x, 纵坐标长度为 y(取数组两端的最小值 ),求一个面积最大的长方形。
s = x*y
调整x和y值 达到 s最大。
class Solution {
public:
int maxArea(vector& height) {
int l =0;
int h = height.size();
int vol =0;
h--;
int max=0;
while(lheight[h]?height[h]:height[l];
vol = min*(h-l);
if(vol>max)
max = vol;
if(height[l]