求最大子矩阵的大小

这个题考察的是动态规划,并且要了解LeetCode第84题,要清楚直方图的面积怎么计算。

85.最大矩阵(LeetCode)

题目

给定一个仅包含 0 和 1 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。

示例输入:

[
  ["1","0","1","0","0"],
  ["1","0","1","1","1"],
  ["1","1","1","1","1"],
  ["1","0","0","1","0"]
]

示例输出:

输出为:6

解题思路:

  • 首先要明白从第一行到最后一行:从下往上看是一个直方图,如图所示:
9D7B1F960DDCCE29191A06056302D15B.jpg

你可能感兴趣的:(求最大子矩阵的大小)