#1072

Flip Columns For Maximum Number of Equal Rows

pupil · 460 · lc medium +26 · verified · 78.6% accepted · 1,344 likes · top 90%

Description

You are given an m x n binary matrix. You may flip every cell in any chosen subset of columns (changing 0 to 1 and vice versa).

Return the maximum number of rows that have all equal values after performing any number of such column flips.

Example 1:

Input: matrix = [[0,1],[1,1]]
Output: 1
Explanation: After flipping no values, 1 row has all values equal.

Example 2:

Input: matrix = [[0,1],[1,0]]
Output: 2
Explanation: After flipping values in the first column, both rows have equal values.

Example 3:

Input: matrix = [[0,0,0],[0,0,1],[1,1,0]]
Output: 2
Explanation: After flipping values in the first two columns, the last two rows have equal values.

Code

1
2
3