#861
Score After Flipping Matrix
pupil · 440 · lc medium +26 · verified · 80.3% accepted · 2,482 likes · top 92%
Description
You are given an m x n binary matrix grid.
A move consists of selecting any row or column and toggling all its values (flipping 0s to 1s and 1s to 0s).
Interpreting each row as a binary number, the score of the matrix is the sum of all row values.
Return the maximum score achievable after any number of moves (including zero).
Example 1:
Input: grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]
Output: 39
Explanation: 0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
Example 2:
Input: grid = [[0]]
Output: 1
Code
1
2
3