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.
解析: i,j 两点之间,假设i点高度小于j点高度,那他们两点间的容量c=(j - i )* i的高度 ,任意i ,j 之间的一点k 与 i 点组成的水桶容量一定小于i,j之间的容量c。所以i点 与其他点之间的容量就不用算了。
Note: You may not slant the container.
解析: i,j 两点之间,假设i点高度小于j点高度,那他们两点间的容量c=(j - i )* i的高度 ,任意i ,j 之间的一点k 与 i 点组成的水桶容量一定小于i,j之间的容量c。所以i点 与其他点之间的容量就不用算了。
int mymin(int a,int b)
{
return a>=b?b:a;
}
int maxArea(int* height, int heightSize) {
int i=0;
int j=heightSize-1;
int maxV=0;
while(i
maxV?temp:maxV;
if(height[i]