首页 > 其他 > 详细

85. Maximal Rectangle

时间:2016-05-15 09:38:24      阅读:260      评论:0      收藏:0      [点我收藏+]
    /*
     * 85. Maximal Rectangle
     * 12.20 by Mingyang 
     * 这里运用了上次做的 84.Largest Rectangle in
     * Histogram一模一样的题目,这样的话后面的function就不用改了,我们再一层一层的切割,每切一次就是一次新的Histogram题目
     * 我们只需要看新加进来的行(底面)上对应的列元素是不是0,如果是,则高度是0,否则则是上一行直方图的高度加1。
     */
    public int maximalRectangle(char[][] matrix) {
        if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
            return 0;
        }
        int maxArea = 0;
        int[] height = new int[matrix[0].length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                height[j] = matrix[i][j] == ‘0‘ ? 0 : height[j] + 1;
            }
            maxArea = Math.max(largestRectangleArea(height), maxArea);
        }
        return maxArea;
    }

 

85. Maximal Rectangle

原文:http://www.cnblogs.com/zmyvszk/p/5494595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!