Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7d780c7

Browse files
committedApr 2, 2025
Add solution #1072
1 parent 328ab19 commit 7d780c7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,112 LeetCode solutions in JavaScript
1+
# 1,113 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -852,6 +852,7 @@
852852
1047|[Remove All Adjacent Duplicates In String](./solutions/1047-remove-all-adjacent-duplicates-in-string.js)|Easy|
853853
1051|[Height Checker](./solutions/1051-height-checker.js)|Easy|
854854
1071|[Greatest Common Divisor of Strings](./solutions/1071-greatest-common-divisor-of-strings.js)|Easy|
855+
1072|[Flip Columns For Maximum Number of Equal Rows](./solutions/1072-flip-columns-for-maximum-number-of-equal-rows.js)|Medium|
855856
1079|[Letter Tile Possibilities](./solutions/1079-letter-tile-possibilities.js)|Medium|
856857
1081|[Smallest Subsequence of Distinct Characters](./solutions/1081-smallest-subsequence-of-distinct-characters.js)|Medium|
857858
1092|[Shortest Common Supersequence](./solutions/1092-shortest-common-supersequence.js)|Hard|
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* 1072. Flip Columns For Maximum Number of Equal Rows
3+
* https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/
4+
* Difficulty: Medium
5+
*
6+
* You are given an m x n binary matrix matrix.
7+
*
8+
* You can choose any number of columns in the matrix and flip every cell in that column
9+
* (i.e., Change the value of the cell from 0 to 1 or vice versa).
10+
*
11+
* Return the maximum number of rows that have all values equal after some number of flips.
12+
*/
13+
14+
/**
15+
* @param {number[][]} matrix
16+
* @return {number}
17+
*/
18+
var maxEqualRowsAfterFlips = function(matrix) {
19+
const rowPatterns = new Map();
20+
const rows = matrix.length;
21+
const cols = matrix[0].length;
22+
23+
for (let i = 0; i < rows; i++) {
24+
let pattern = '';
25+
let flippedPattern = '';
26+
for (let j = 0; j < cols; j++) {
27+
pattern += matrix[i][j];
28+
flippedPattern += 1 - matrix[i][j];
29+
}
30+
rowPatterns.set(pattern, (rowPatterns.get(pattern) || 0) + 1);
31+
rowPatterns.set(flippedPattern, (rowPatterns.get(flippedPattern) || 0) + 1);
32+
}
33+
34+
let result = 0;
35+
for (const count of rowPatterns.values()) {
36+
result = Math.max(result, count);
37+
}
38+
39+
return result;
40+
};

0 commit comments

Comments
 (0)
Please sign in to comment.