Skip to content

Commit de75429

Browse files
committed
feat: update solutions to lc problem: No.1072
No.1072.Flip Columns For Maximum Number of Equal Rows
1 parent 19d3802 commit de75429

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ class Solution:
9797
class Solution {
9898
public int maxEqualRowsAfterFlips(int[][] matrix) {
9999
Map<String, Integer> cnt = new HashMap<>();
100-
int ans = 0;
100+
int ans = 0, n = matrix[0].length;
101101
for (var row : matrix) {
102-
var sb = new StringBuilder();
103-
for (int x : row) {
104-
sb.append(row[0] == 0 ? x : x ^ 1);
102+
char[] cs = new char[n];
103+
for (int i = 0; i < n; ++i) {
104+
cs[i] = (char) (row[0] ^ row[i]);
105105
}
106-
ans = Math.max(ans, cnt.merge(sb.toString(), 1, Integer::sum));
106+
ans = Math.max(ans, cnt.merge(String.valueOf(cs), 1, Integer::sum));
107107
}
108108
return ans;
109109
}

solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/README_EN.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class Solution:
6767
class Solution {
6868
public int maxEqualRowsAfterFlips(int[][] matrix) {
6969
Map<String, Integer> cnt = new HashMap<>();
70-
int ans = 0;
70+
int ans = 0, n = matrix[0].length;
7171
for (var row : matrix) {
72-
var sb = new StringBuilder();
73-
for (int x : row) {
74-
sb.append(row[0] == 0 ? x : x ^ 1);
72+
char[] cs = new char[n];
73+
for (int i = 0; i < n; ++i) {
74+
cs[i] = (char) (row[0] ^ row[i]);
7575
}
76-
ans = Math.max(ans, cnt.merge(sb.toString(), 1, Integer::sum));
76+
ans = Math.max(ans, cnt.merge(String.valueOf(cs), 1, Integer::sum));
7777
}
7878
return ans;
7979
}

solution/1000-1099/1072.Flip Columns For Maximum Number of Equal Rows/Solution.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class Solution {
22
public int maxEqualRowsAfterFlips(int[][] matrix) {
33
Map<String, Integer> cnt = new HashMap<>();
4-
int ans = 0;
4+
int ans = 0, n = matrix[0].length;
55
for (var row : matrix) {
6-
var sb = new StringBuilder();
7-
for (int x : row) {
8-
sb.append(row[0] == 0 ? x : x ^ 1);
6+
char[] cs = new char[n];
7+
for (int i = 0; i < n; ++i) {
8+
cs[i] = (char) (row[0] ^ row[i]);
99
}
10-
ans = Math.max(ans, cnt.merge(sb.toString(), 1, Integer::sum));
10+
ans = Math.max(ans, cnt.merge(String.valueOf(cs), 1, Integer::sum));
1111
}
1212
return ans;
1313
}

solution/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def get_contests(fetch_new=True) -> List:
391391
generate_summary(ls)
392392

393393
# 生成周赛题目列表
394-
# generate_contest_readme(cls)
394+
generate_contest_readme(cls)
395395

396396
# 刷新题目文件
397397
if refresh_all:

0 commit comments

Comments
 (0)