Skip to content

Commit 1fbb79d

Browse files
committed
Runtime: 1058 ms (Top 6.78%) | Memory: 15.2 MB (Top 89.63%)
1 parent 1ce7488 commit 1fbb79d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/algorithms/M/Maximal Rectangle/Maximal Rectangle.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
# Runtime: 1058 ms (Top 6.78%) | Memory: 15.2 MB (Top 89.63%)
12
class Solution:
23
def maxArea(self,arr: List[List[int]]) -> int:
34
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
56
arr.append(-1) # value for stack index -1 and one extra iteration to empty the stack
67
for i in range(len(arr)): # traversing for stack from left to right
78
arr[i] = int(arr[i]) # we are getting str value from matrix
@@ -14,12 +15,12 @@ def maxArea(self,arr: List[List[int]]) -> int:
1415
"""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"""
1516
# r1 - 1 0 1 0 0
1617
# 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+
1920
# r1 - 1 1 1 0 1
2021
# 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+
2324
def maximalRectangle(self, matrix: List[List[str]]) -> int:
2425
result = [0] * len(matrix[0])
2526
maxReact = 0
@@ -33,4 +34,3 @@ def maximalRectangle(self, matrix: List[List[str]]) -> int:
3334
result[j] = result[j] + matrix[i][j]
3435
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
3536
return maxReact
36-

0 commit comments

Comments
 (0)