代码:
public class Solution {
public int maxArea(int[] height) {
int low = 0;
int high = height.length - 1;
if(high < 1) return 0;
int maxArea = 0;
while(low < high){
int area = (high - low) * (height[low] < height[high] ? height[low] : height[high]);
if(area > maxArea) maxArea = area;
if(height[low] < height[high]){
while(low < high && height[low+1] <= height[low]) low++;
low++;
}
else{
while(low < high && height[high-1] <= height[high]) high--;
high--;
}
}
return maxArea;
}
}
Jan 14 - Container with Most Water; Array; Two Pointer;
原文:http://www.cnblogs.com/5683yue/p/5132207.html