Skip to content

Commit 3a12bae

Browse files
committed
Runtime: 3042 ms (Top 5.00%) | Memory: 37.6 MB (Top 80.63%)
1 parent 47730a3 commit 3a12bae

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/algorithms/L/Largest Submatrix With Rearrangements/Largest Submatrix With Rearrangements.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// Runtime: 3042 ms (Top 5.00%) | Memory: 37.6 MB (Top 80.63%)
12
from collections import Counter
23

34
class Solution:
45
def largestSubmatrix(self, matrix: List[List[int]]) -> int:
56
M = len(matrix)
67
N = len(matrix[0])
7-
8+
89
colcons = [] # preprocess columns
910
for c in range(N):
1011
cons = []
@@ -17,7 +18,7 @@ def largestSubmatrix(self, matrix: List[List[int]]) -> int:
1718
cons.append(s)
1819
colcons.append(cons)
1920
# colcons[c][r] is how much 1's we'll get if we start from column c at row r and go up
20-
21+
2122
best = 0
2223
for r in range(M):
2324
# try r as the lowest row
@@ -26,4 +27,4 @@ def largestSubmatrix(self, matrix: List[List[int]]) -> int:
2627
cs = accumulate(C[v] for v in vs)
2728
for v,c in zip(vs,cs):
2829
best = max(best,v*c)
29-
return best
30+
return best

0 commit comments

Comments
 (0)