Skip to content

Commit e6aa2ea

Browse files
committed
update
1 parent e0503bf commit e6aa2ea

6 files changed

+1297
-11
lines changed

Diff for: .babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

Diff for: largest-rectangle-in-histogram.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
*/
2929

3030
/**
31+
* Get the largest rectangle area
3132
* @param {number[]} heights
3233
* @return {number}
34+
* @time complexity: O(n)
35+
* @space complexity: O(n)
3336
*/
3437
const largestRectangleArea = heights => {
3538

@@ -54,6 +57,15 @@ const largestRectangleArea = heights => {
5457
return maxArea;
5558
};
5659

60+
/**
61+
* Calcualte the area
62+
* @param {number} i index element in heights
63+
* @param {number[]} heights
64+
* @param {number[]} stack
65+
* @return {number}
66+
* @time complexity: O(1)
67+
* @space complexity: O(1)
68+
*/
5769
const getArea = (i, heights, stack) => {
5870
const h = heights[stack.pop()],
5971
w = stack.length ? i - stack[stack.length-1] - 1 : i;
@@ -62,22 +74,20 @@ const getArea = (i, heights, stack) => {
6274
};
6375

6476

65-
const assert = require('chai').assert;
77+
import { assert } from 'chai';
6678

6779
describe('Largest Rectangle in Histogram', () => {
6880

6981
it('should find the longest path', () => {
70-
const input = [2,1,5,6,2,3],
71-
output = 10;
72-
73-
assert.strictEqual(largestRectangleArea(input), output);
82+
assert.strictEqual(largestRectangleArea([2,1,5,6,2,3]), 10);
7483
});
7584

7685
it('should return 2 for [1, 1]', () => {
77-
const input = [1, 1],
78-
output = 2;
86+
assert.strictEqual(largestRectangleArea([1, 1]), 2);
87+
});
7988

80-
assert.strictEqual(largestRectangleArea(input), output);
81-
})
89+
it('should return 1 for [1]', () => {
90+
assert.strictEqual(largestRectangleArea([1]), 1);
91+
});
8292

8393
});

0 commit comments

Comments
 (0)