3239.cpp (532B)
1 class Solution { 2 public: 3 int minFlips(const vector<vector<int>> &grid) const { 4 const int n = size(grid), m = size(grid[0]); 5 int row = 0, col = 0; 6 7 for (int i = 0; i < n; i++) { 8 int a = 0, b = m - 1; 9 while (a < b) 10 row += grid[i][a++] != grid[i][b--]; 11 } 12 13 for (int j = 0; j < m; j++) { 14 int a = 0, b = n - 1; 15 while (a < b) 16 col += grid[a++][j] != grid[b--][j]; 17 } 18 19 return min(row, col); 20 } 21 };