Largest Rectangle in Histogram(直方图最大矩形覆盖)

http://www.lintcode.com/en/problem/largest-rectangle-in-histogram/?rand=true

public class Solution {
    /*
     * @param height: A list of integer
     * @return: The area of largest rectangle in the histogram
     */
    public int largestRectangleArea(int[] height) {
        // write your code here
        int max = 0;
        for (int i = 0; i < height.length; i++) {
            int min = height[i];
            for (int j = i; j < height.length; j++) {
//                面积是由是小值来决定的,所以记录下最小化值乘以宽度
                min = Math.min(min, height[j]);
                max = Math.max(max, min * (j - i + 1));
            }
        }
        return max;
    }
}

你可能感兴趣的:(Largest Rectangle in Histogram(直方图最大矩形覆盖))