3239. Minimum Number of Flips to Make Binary Grid Palindromic I Medium

@problem@discussion
#Array#Two Pointers#Matrix



1/**
2 * [3239] Minimum Number of Flips to Make Binary Grid Palindromic I
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 either all rows palindromic or all columns palindromic.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">grid = [[1,0,0],[0,0,0],[0,0,1]]</span>
12 * Output: <span class="example-io">2</span>
13 * Explanation:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-20-10.png" style="width: 420px; height: 108px;" />
15 * Flipping the highlighted cells makes all the rows palindromic.
16 * </div>
17 * <strong class="example">Example 2:
18 * <div class="example-block">
19 * Input: <span class="example-io">grid = </span>[[0,1],[0,1],[0,0]]
20 * Output: <span class="example-io">1</span>
21 * Explanation:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/07/screenshot-from-2024-07-08-00-31-23.png" style="width: 300px; height: 100px;" />
23 * Flipping the highlighted cell makes all the columns palindromic.
24 * </div>
25 * <strong class="example">Example 3:
26 * <div class="example-block">
27 * Input: <span class="example-io">grid = [[1],[0]]</span>
28 * Output: <span class="example-io">0</span>
29 * Explanation:
30 * All rows are already palindromic.
31 * </div>
32 *  
33 * Constraints:
34 * 
35 * 	m == grid.length
36 * 	n == grid[i].length
37 * 	1 <= m * n <= 2 * 10^5
38 * 	0 <= grid[i][j] <= 1
39 * 
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-i/
44// discuss: https://leetcode.com/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-i/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49    pub fn min_flips(grid: Vec<Vec<i32>>) -> i32 {
50        0
51    }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59
60    #[test]
61    fn test_3239() {
62    }
63}
64


Back
© 2025 bowen.ge All Rights Reserved.