-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1072.py
More file actions
28 lines (24 loc) · 765 Bytes
/
1072.py
File metadata and controls
28 lines (24 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from typing import List
from collections import Counter
class Solution:
def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int:
cnt = Counter()
for row in matrix:
p0 = tuple(i for i, x in enumerate(row) if not x)
p1 = tuple(i for i, x in enumerate(row) if x)
if p0 > p1:
p0, p1 = p1, p0
cnt[p0] += 1
cnt[p1] += 1
return cnt.most_common(1)[0][1]
if __name__ == '__main__':
cases = [
([[0,1],[1,1]], 1),
([[0,1],[1,0]], 2),
([[0,0,0],[0,0,1],[1,1,0]], 2),
]
sln = Solution()
for matrix, golden in cases:
res = sln.maxEqualRowsAfterFlips(matrix)
print(golden, res)
assert golden == res