Skip to content

Commit 9ed6967

Browse files
committed
Day83
1 parent 05bfa97 commit 9ed6967

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Day83/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
* @param {number[]} heights
33
* @return {number}
44
*/
5-
var largestRectangleArea = function(h) {
5+
var largestRectangleArea = function (h) {
66
let area = 0;
77

8-
if(h.length == 1)return h[0];
8+
if (h.length == 1) return h[0];
99

10-
for(let i=0; i < h.length; i++){
10+
for (let i = 0; i < h.length; i++) {
1111
let currH = h[i]
12-
for(let j = i; j < h.length; j++){
12+
for (let j = i; j < h.length; j++) {
1313
currH = Math.min(currH, h[j]);
14-
area = Math.max(area,currH * (j-i+1) )
14+
area = Math.max(area, currH * (j - i + 1))
1515
}
1616
}
1717

@@ -24,24 +24,24 @@ var largestRectangleArea = function(h) {
2424
* @param {number[]} heights
2525
* @return {number}
2626
*/
27-
var largestRectangleArea = function(heights) {
27+
var largestRectangleArea = function (heights) {
2828

2929
let area = 0;
3030
let stack = [];
3131
heights.push(0);
3232
heights.unshift(0);
3333

34-
for(let i=0; i < heights.length; i++){
34+
for (let i = 0; i < heights.length; i++) {
3535
let curr = heights[i];
3636

37-
while(stack && heights[stack[stack.length-1]] > curr){
37+
while (stack && heights[stack[stack.length - 1]] > curr) {
3838
let j = stack.pop();
3939
let width;
4040

41-
if(stack.length==0){
42-
width =1
43-
}else{
44-
width = i - stack[stack.length-1] -1;
41+
if (stack.length == 0) {
42+
width = 1
43+
} else {
44+
width = i - stack[stack.length - 1] - 1;
4545
}
4646

4747
area = Math.max(area, width * heights[j])

0 commit comments

Comments
 (0)