代码:

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;
    }
}

  

posted on 2016-01-15 07:07  爱推理的骑士  阅读(119)  评论(0编辑  收藏  举报