We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 82273c5 commit b80c50cCopy full SHA for b80c50c
84-largest-rectangle-in-histogram.js
@@ -58,3 +58,24 @@ const largestRectangleArea = function(heights) {
58
}
59
return max;
60
};
61
+
62
+// another
63
64
+/**
65
+ * @param {number[]} heights
66
+ * @return {number}
67
+ */
68
+const largestRectangleArea = function(heights) {
69
+ heights.push(0)
70
+ const st = [], n = heights.length
71
+ let res = 0
72
+ for(let i = 0; i <= n; i++) {
73
+ while(st.length && heights[st[st.length - 1]] >= heights[i]) {
74
+ const top = st.pop()
75
+ const pre = st.length ? st[st.length - 1] : -1
76
+ res = Math.max(res, heights[top] * (i - pre - 1))
77
+ }
78
+ st.push(i)
79
80
+ return res
81
+};
0 commit comments