3240. Minimum Number of Flips to Make Binary Grid Palindromic II Medium
1/**
2 * [3240] Minimum Number of Flips to Make Binary Grid Palindromic II
3 *
4 * You are given an m x n binary matrix grid.
5 * A row or column is considered palindromic if its values read the same forward and backward.
6 * You can flip any number of cells in grid from 0 to 1, or from 1 to 0.
7 * Return the minimum number of cells that need to be flipped to make all rows and columns palindromic, and the total number of 1's in grid divisible by 4.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">grid = [[1,0,0],[0,1,0],[0,0,1]]</span>
12 * Output: <span class="example-io">3</span>
13 * Explanation:
14 * <img src="https://assets.leetcode.com/uploads/2024/08/01/image.png" style="width: 400px; height: 105px;" />
15 * </div>
16 * <strong class="example">Example 2:
17 * <div class="example-block">
18 * Input: <span class="example-io">grid = [[0,1],[0,1],[0,0]]</span>
19 * Output: <span class="example-io">2</span>
20 * Explanation:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/08/screenshot-from-2024-07-09-01-37-48.png" style="width: 300px; height: 104px;" />
22 * </div>
23 * <strong class="example">Example 3:
24 * <div class="example-block">
25 * Input: <span class="example-io">grid = [[1],[1]]</span>
26 * Output: <span class="example-io">2</span>
27 * Explanation:
28 * <img alt="" src="https://assets.leetcode.com/uploads/2024/08/01/screenshot-from-2024-08-01-23-05-26.png" style="width: 200px; height: 70px;" />
29 * </div>
30 *
31 * Constraints:
32 *
33 * m == grid.length
34 * n == grid[i].length
35 * 1 <= m * n <= 2 * 10^5
36 * 0 <= grid[i][j] <= 1
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-ii/
42// discuss: https://leetcode.com/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-ii/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn min_flips(grid: Vec<Vec<i32>>) -> i32 {
48 0
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_3240() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.