File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,112 LeetCode solutions in JavaScript
1
+ # 1,113 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
852
852
1047|[ Remove All Adjacent Duplicates In String] ( ./solutions/1047-remove-all-adjacent-duplicates-in-string.js ) |Easy|
853
853
1051|[ Height Checker] ( ./solutions/1051-height-checker.js ) |Easy|
854
854
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|
855
856
1079|[ Letter Tile Possibilities] ( ./solutions/1079-letter-tile-possibilities.js ) |Medium|
856
857
1081|[ Smallest Subsequence of Distinct Characters] ( ./solutions/1081-smallest-subsequence-of-distinct-characters.js ) |Medium|
857
858
1092|[ Shortest Common Supersequence] ( ./solutions/1092-shortest-common-supersequence.js ) |Hard|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments