Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing only 1’s and return its area.
For example, given the following matrix:
Return 6.
解法1:
这题是运用了Largest Rectangle Area那题的解法。因为这题可以看成是一行一行的数字叠加起来,组成了一个histogram,求最大的面积。
那么实际的算法就是对于每一层,计算一个当前累积的histogram,然后再求一个最大面积就可以了。
C++
Java