861. Score After Flipping Matrix Medium
1/**
2 * [861] Score After Flipping Matrix
3 *
4 * You are given an m x n binary matrix grid.
5 * A move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).
6 * Every row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.
7 * Return the highest possible score after making any number of moves (including zero moves).
8 *
9 * Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2021/07/23/lc-toogle1.jpg" style="width: 500px; height: 299px;" />
11 * Input: grid = [[0,0,1,1],[1,0,1,0],[1,1,0,0]]
12 * Output: 39
13 * Explanation: 0b1111 + 0b1001 + 0b1111 = 15 + 9 + 15 = 39
14 *
15 * Example 2:
16 *
17 * Input: grid = [[0]]
18 * Output: 1
19 *
20 *
21 * Constraints:
22 *
23 * m == grid.length
24 * n == grid[i].length
25 * 1 <= m, n <= 20
26 * grid[i][j] is either 0 or 1.
27 *
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/score-after-flipping-matrix/
32// discuss: https://leetcode.com/problems/score-after-flipping-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37 pub fn matrix_score(grid: Vec<Vec<i32>>) -> i32 {
38 0
39 }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn test_861() {
50 }
51}
52
Back
© 2025 bowen.ge All Rights Reserved.