力扣最大面积最大矩形
给定一个由
0
和
1
填充的二维二进制矩阵,找到仅包含
1
的最大矩形并返回其面积。
Example:
Input:
[
["1","0","1","0","0"],
["1","0","1","1","1"],
["1","1","1","1","1"],
["1","0","0","1","0"]
]
Output:
6
执行
:
class
Solution
{
public
int
largestRectangleArea
(
int
[]
heights
)
{
Stack<
Integer
>
stack
=
new
Stack<>
();
int
maxArea
=
0
;
int
index
=
0
;
while
(index
<
heights
.
length)
{
if
(stack
.
empty()
||
heights[index]
>=
heights[stack
.
peek()])
{
stack
.
push(index
++
);
}
else
{
int
top
=
stack
.
pop();
int
width
=
2021-07-08 09:06:36
1KB
系统开源
1