We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent caaef5d commit 2f3d493Copy full SHA for 2f3d493
84.柱状图中最大的矩形.js
@@ -0,0 +1,30 @@
1
+/*
2
+ * @lc app=leetcode.cn id=84 lang=javascript
3
+ *
4
+ * [84] 柱状图中最大的矩形
5
+ */
6
+
7
+// @lc code=start
8
+/**
9
+ * @param {number[]} heights
10
+ * @return {number}
11
12
+var largestRectangleArea = function(heights) {
13
+ let result = 0;
14
+ const stack = [-1];
15
+ for (let i = 0; i < heights.length; i++) {
16
+ while (stack[stack.length - 1] !== -1 && heights[stack[stack.length - 1]] >= heights[i]) {
17
+ const j = stack.pop();
18
+ result = Math.max(result, heights[j] * (i - stack[stack.length - 1] - 1));
19
+ }
20
+ stack.push(i);
21
22
23
+ while (stack[stack.length - 1] !== -1) {
24
25
+ result = Math.max(result, heights[j] * (heights.length - stack[stack.length - 1] - 1));
26
27
28
+ return result;
29
+};
30
+// @lc code=end
0 commit comments