FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/maximalrectangle.java at master · wpande/leetcode · GitHub
wpande
leetcode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
maximalrectangle.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (62 loc) · 1.76 KB
Breadcrumbs
leetcode
/
maximalrectangle.java
Copy path
File metadata and controls
63 lines (62 loc) · 1.76 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public
class
Solution
{
public
int
solve
(
int
[]
histg
){
Stack
<
Integer
>
st
=
new
Stack
<
Integer
>();
int
len
=
histg
.
length
;
if
(
len
==
1
)
return
0
;
int
idx
=
0
;
int
ret
=
0
;
st
.
push
(
idx
++);
while
(
idx
<
len
){
if
(
st
.
empty
()||
histg
[
st
.
peek
()]<
histg
[
idx
])
st
.
push
(
idx
++);
else
{
while
(!
st
.
empty
()&&
histg
[
st
.
peek
()]>=
histg
[
idx
]){
int
area
=
histg
[
st
.
pop
()]*(
st
.
empty
()?
idx
:
idx
-
st
.
peek
()-
1
);
if
(
area
>
ret
)
ret
=
area
;
}
}
}
return
ret
;
}
public
int
maximalRectangle
(
char
[][]
matrix
) {
int
lenx
=
matrix
.
length
;
int
res
=
0
;
if
(
lenx
<
1
)
return
0
;
int
leny
=
matrix
[
0
].
length
;
if
(
leny
<
1
)
return
0
;
int
[][]
hist
=
new
int
[
lenx
+
1
][
leny
+
1
];
Stack
<
Integer
>
st
=
new
Stack
<
Integer
>();
int
buf
=
0
;
for
(
int
j
=
0
;
j
<
leny
;
j
++)
for
(
int
i
=
0
;
i
<
lenx
+
1
;
i
++){
if
(
i
==
lenx
){
while
(!
st
.
empty
()){
buf
=
st
.
pop
();
hist
[
buf
][
j
]=
i
-
buf
;
}
}
else
{
if
(
matrix
[
i
][
j
]==
'0'
){
hist
[
i
][
j
]=
0
;
while
(!
st
.
empty
()){
buf
=
st
.
pop
();
hist
[
buf
][
j
]=
i
-
buf
;
}
}
else
{
st
.
push
(
i
);
}
}
}
for
(
int
i
=
0
;
i
<
lenx
;
i
++){
int
ret
=
solve
(
hist
[
i
]);
if
(
ret
>
res
)
res
=
ret
;
}
return
res
;
}
}
Back
|
FazBrowse Home
|
New Git URL