Open Tcdian opened 4 years ago
func maxEqualRowsAfterFlips(matrix [][]int) int {
record := make(map[string]int);
maxResult := 0;
for _, row := range matrix {
origin := "";
flipped := "";
for _, number := range row {
if number == 0 {
origin += "0";
flipped += "1";
} else {
origin += "1";
flipped += "0";
}
}
record[origin] += 1;
record[flipped] += 1;
maxResult = max(maxResult, max(record[origin], record[flipped]));
}
return maxResult;
}
func max(a int, b int) int {
if a > b {
return a;
}
return b;
}
1072. Flip Columns For Maximum Number of Equal Rows
给定由若干 0 和 1 组成的矩阵
matrix
,从中选出任意数量的列并翻转其上的 每个 单元格。翻转后,单元格的值从 0 变成 1,或者从 1 变为 0 。返回经过一些翻转后,行上所有值都相等的最大行数。
Example 1
Example 2
Example 3
Constraints
1 <= matrix.length <= 300
1 <= matrix[i].length <= 300
matrix[i].length
's are equalmatrix[i][j] is 0 or 1