File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
src/main/scala/g0001_0100/s0084_largest_rectangle_in_histogram Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1
1
package g0001_0100 .s0084_largest_rectangle_in_histogram
2
2
3
3
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Stack #Monotonic_Stack
4
- // #Big_O_Time_O(n_log_n)_Space_O(log_n) #2023_11_02_Time_904_ms_(71.43%)_Space_77.5_MB_(35.71%)
4
+ // #Big_O_Time_O(n_log_n)_Space_O(log_n) #2024_06_02_Time_1092_ms_(71.43%)_Space_76.1_MB_(64.29%)
5
+
6
+ import scala .util .control .Breaks .{break , breakable }
5
7
6
8
object Solution {
7
9
def largestRectangleArea (heights : Array [Int ]): Int = {
@@ -54,12 +56,16 @@ object Solution {
54
56
}
55
57
56
58
private def checkIfSorted (a : Array [Int ], start : Int , limit : Int ): Boolean = {
57
- for (i <- start + 1 until limit) {
58
- if (a(i) < a(i - 1 )) {
59
- return false
59
+ var sorted = true
60
+ breakable {
61
+ for (i <- start + 1 until limit) {
62
+ if (a(i) < a(i - 1 )) {
63
+ sorted = false
64
+ break
65
+ }
60
66
}
61
67
}
62
- true
68
+ sorted
63
69
}
64
70
65
71
private def maxOfThreeNums (a : Int , b : Int , c : Int ): Int = {
You can’t perform that action at this time.
0 commit comments