File tree 1 file changed +6
-6
lines changed
scripts/algorithms/M/Maximal Rectangle
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 1058 ms (Top 6.78%) | Memory: 15.2 MB (Top 89.63%)
1
2
class Solution :
2
3
def maxArea (self ,arr : List [List [int ]]) -> int :
3
4
maxA = 0 #local max variable to return max area of a 1D array
4
- stack = [- 1 ] #initializing with minimum value so we can avoid using loop for remaining element in the stack after whole traversing
5
+ stack = [- 1 ] #initializing with minimum value so we can avoid using loop for remaining element in the stack after whole traversing
5
6
arr .append (- 1 ) # value for stack index -1 and one extra iteration to empty the stack
6
7
for i in range (len (arr )): # traversing for stack from left to right
7
8
arr [i ] = int (arr [i ]) # we are getting str value from matrix
@@ -14,12 +15,12 @@ def maxArea(self,arr: List[List[int]]) -> int:
14
15
"""Below is the code for adding each row one by one and passing it to above function to get the max area for each row"""
15
16
# r1 - 1 0 1 0 0
16
17
# r2 - 1 0 1 1 1
17
- # r = 2 0 2 1 1 This is for else condition
18
-
18
+ # r = 2 0 2 1 1 This is for else condition
19
+
19
20
# r1 - 1 1 1 0 1
20
21
# r2 - 1 0 1 1 0
21
- # r = 2 0 2 1 0 This is for if condition
22
-
22
+ # r = 2 0 2 1 0 This is for if condition
23
+
23
24
def maximalRectangle (self , matrix : List [List [str ]]) -> int :
24
25
result = [0 ] * len (matrix [0 ])
25
26
maxReact = 0
@@ -33,4 +34,3 @@ def maximalRectangle(self, matrix: List[List[str]]) -> int:
33
34
result [j ] = result [j ] + matrix [i ][j ]
34
35
maxReact = max (maxReact ,self .maxArea (result )) #after getting max area for 1D arr we are getting max value from those 1D arr for the 2D arr
35
36
return maxReact
36
-
You can’t perform that action at this time.
0 commit comments