Skip to content

Commit 625443f

Browse files
authored
Create Solution.java
1 parent 77314ab commit 625443f

File tree

1 file changed

+19
-0
lines changed
  • solution/1072.Flip Columns For Maximum Number of Equal Rows

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int maxEqualRowsAfterFlips(int[][] matrix) {
3+
Map<String, Integer> map = new HashMap<>();
4+
for (int[] row : matrix) {
5+
if (row[0] == 1) {
6+
for (int i = 0; i < row.length; ++i) {
7+
row[i] ^= 1;
8+
}
9+
}
10+
StringBuilder sb = new StringBuilder();
11+
for (int x : row) {
12+
sb.append(x);
13+
}
14+
String s = sb.toString();
15+
map.put(s, map.getOrDefault(s, 0) + 1);
16+
}
17+
return map.values().stream().max(Integer::compareTo).get();
18+
}
19+
}

0 commit comments

Comments
 (0)