Skip to content

Commit ed2d8e3

Browse files
committed
Format
1 parent a4b37e0 commit ed2d8e3

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

largest-rectangle.js

+17-25
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,30 @@ function readLine() {
2727
// Complete the largestRectangle function below.
2828
function largestRectangle(h) {
2929
let max = Number.MIN_VALUE;
30-
for (var i = 0; i < h.length; i++) {
31-
let l = i - 1;
32-
let r = i + 1;
33-
let m = 1;
34-
while (l > -1) {
35-
if (h[l] >= h[i]) {
36-
// console.log("left", l)
37-
m++;
38-
}
39-
else {
30+
for (var ith = 0; ith < h.length; ith++) {
31+
let left = ith - 1;
32+
let right = ith + 1;
33+
let buildings = 1;
34+
while (left > -1) {
35+
if (h[left] >= h[ith])
36+
buildings++;
37+
else
4038
break;
41-
}
42-
l--;
39+
left--;
4340
}
44-
while (h.length > r) {
45-
// console.log("right", r)
46-
if (h[r] >= h[i]) {
47-
m++;
48-
}
49-
else {
41+
while (h.length > right) {
42+
if (h[right] >= h[ith])
43+
buildings++;
44+
else
5045
break;
51-
}
52-
r++;
46+
right++;
5347
}
54-
console.log("mcount", m, h[i])
55-
if (m * h[i] > max) {
56-
max = m * h[i];
48+
if (buildings * h[ith] > max) {
49+
max = buildings * h[ith];
5750
}
58-
m = 1;
51+
buildings = 1;
5952
}
6053
return max;
61-
6254
}
6355

6456
function main() {

0 commit comments

Comments
 (0)