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;
}
};
1252. Cells with Odd Values in a Matrix
猜你喜欢
转载自blog.csdn.net/zeroQiaoba/article/details/104691296
今日推荐
周排行