File tree 1 file changed +20
-15
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +20
-15
lines changed Original file line number Diff line number Diff line change 19
19
*/
20
20
public class _84 {
21
21
22
- /**credit: https://leetcode.com/articles/largest-rectangle-histogram/#approach-5-using-stack-accepted
23
- * and https://discuss.leetcode.com/topic/7599/o-n-stack-based-java-solution*/
22
+ public static class Solution1 {
23
+
24
+ /**
25
+ * credit: https://leetcode.com/articles/largest-rectangle-histogram/#approach-5-using-stack-accepted
26
+ * and https://discuss.leetcode.com/topic/7599/o-n-stack-based-java-solution
27
+ */
24
28
public int largestRectangleArea (int [] heights ) {
25
- int len = heights .length ;
26
- Stack <Integer > s = new Stack <>();
27
- int maxArea = 0 ;
28
- for (int i = 0 ; i <= len ; i ++) {
29
- int h = (i == len ? 0 : heights [i ]);
30
- if (s .isEmpty () || h >= heights [s .peek ()]) {
31
- s .push (i );
32
- } else {
33
- int tp = s .pop ();
34
- maxArea = Math .max (maxArea , heights [tp ] * (s .isEmpty () ? i : i - 1 - s .peek ()));
35
- i --;
36
- }
29
+ int len = heights .length ;
30
+ Stack <Integer > s = new Stack <>();
31
+ int maxArea = 0 ;
32
+ for (int i = 0 ; i <= len ; i ++) {
33
+ int h = (i == len ? 0 : heights [i ]);
34
+ if (s .isEmpty () || h >= heights [s .peek ()]) {
35
+ s .push (i );
36
+ } else {
37
+ int tp = s .pop ();
38
+ maxArea = Math .max (maxArea , heights [tp ] * (s .isEmpty () ? i : i - 1 - s .peek ()));
39
+ i --;
37
40
}
38
- return maxArea ;
41
+ }
42
+ return maxArea ;
39
43
}
44
+ }
40
45
41
46
}
You can’t perform that action at this time.
0 commit comments