Flip Columns For Max Equal Rows
找到数量最多的具有相同pattern的row,它的数量就是最多的equal rows的数量。
以下是一些相同pattern的例子
1,0,0 -> 0,1,1
1,0,1 -> 0,1,0
1,1,1 -> 0,0,0
0,0,0 -> 0,0,0
from collections import defaultdict
class Solution:
def maxEqualRowsAfterFlips(self, matrix: List[List[int]]) -> int:
d = defaultdict(int)
for row in matrix:
d[str(row)]+=1
trans = []
for a in row:
trans.append(1-a)
d[str(trans)]+=1
return max(d.values())
PreviousMaximum Score Words Formed by LettersNextLongest Common Substring (Shortest Common Superstring)
Last updated
Was this helpful?