Advertisement

LeetCode 085: Maximum rectangle in a two-dimensional matrix

阅读量:

题目:

Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.

Example:

Input:
[
[“1”,“0”,“1”,“0”,“0”],
[“1”,“0”,“1”,“1”,“1”],
[“1”,“1”,“1”,“1”,“1”],
[“1”,“0”,“0”,“1”,“0”]
]
Output: 6

翻译:

针对一个由0和1组成的二维二进制矩阵,要求确定其中仅包含1的最大矩形区域,并计算并返回该区域的面积。
示例:
输入:
(
["1", "0", "1", "0", "0"],
["1", "0", "1", "1", "1"],
["1", "1", "1", "1", "1"],
["1", "0", "0", "1", "0"]
)
输出:6

直方图最大矩形面积问题解析

方法一:基于Largest Rectangle in Histogram

若将矩阵沿某一行进行分割,并将该行视为底面,那么从底面向上构成的结构可被视作一个直方图。直方图中每个条形的高度对应于从底面行向上连续单

全部评论 (0)

还没有任何评论哟~