FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode/LarestRectangleInHistogram.java at master · Orio77/LeetCode · GitHub
Orio77
/
LeetCode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode
/
LarestRectangleInHistogram.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (29 loc) · 932 Bytes
Breadcrumbs
LeetCode
/
LarestRectangleInHistogram.java
Copy path
File metadata and controls
32 lines (29 loc) · 932 Bytes
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
import
java
.
util
.
Stack
;
class
Solution
{
public
int
largestRectangleArea
(
int
[]
heights
) {
Stack
<
int
[]>
stack
=
new
Stack
<>();
int
start
;
int
index
;
int
height
;
int
[]
element
;
int
maxArea
=
0
;
for
(
int
i
=
0
;
i
<
heights
.
length
;
i
++) {
start
=
i
;
while
(!
stack
.
isEmpty
() &&
stack
.
peek
()[
1
] >
heights
[
i
]) {
element
=
stack
.
pop
();
index
=
element
[
0
];
height
=
element
[
1
];
maxArea
=
Math
.
max
(
maxArea
,
height
* (
i
-
index
));
start
=
index
;
}
stack
.
push
(
new
int
[]{
start
,
heights
[
i
]});
}
while
(!
stack
.
isEmpty
()) {
element
=
stack
.
pop
();
index
=
element
[
0
];
height
=
element
[
1
];
maxArea
=
Math
.
max
(
maxArea
,
height
* (
heights
.
length
-
index
));
}
return
maxArea
;
}
}
Back
|
FazBrowse Home
|
New Git URL