1252. Cells with Odd Values in a Matrix

class Solution {
public:
    int oddCells(int n, int m, vector<vector<int>>& indices) {
        vector<int> temp(m, 0);
        vector<vector<int>> cnt(n, temp);
        
        for(int i=0;i<indices.size();i++){
            int x = indices[i][0];
            int y = indices[i][1];
            for(int j=0;j<m;j++){
                cnt[x][j] ++;
            }
            for(int j=0;j<n;j++){
                cnt[j][y] ++;
            }
        }
        
        int count = 0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if (cnt[i][j]%2==1){
                    count ++;
                }
            }
        }
        return count;
    }
};
发布了425 篇原创文章 · 获赞 18 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/zeroQiaoba/article/details/104691296