# LeetCode - 1252. Cells with Odd Values in a Matrix ### 題目網址:https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/ ###### tags: `LeetCode` `Easy` ```cpp= /* -LeetCode format- Problem: 1252. Cells with Odd Values in a Matrix Difficulty: Easy by Inversionpeter */ class Solution { public: int oddCells(int m, int n, vector<vector<int>>& indices) { int *rowCounts = new int[m](), *columnCounts = new int[n](), rowOdds = 0, columnOdds = 0; for (vector <int> &index : indices) { ++rowCounts[index[0]]; ++columnCounts[index[1]]; } for (int i = 0; i < m; ++i) if (rowCounts[i] & 1) ++rowOdds; for (int i = 0; i < n; ++i) if (columnCounts[i] & 1) ++columnOdds; return rowOdds * n + columnOdds * (m - (rowOdds << 1)); } }; ```