Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-10-17_00-31-15.png
64.1 KB
#N1252. Cells with Odd Values in a Matrix
problem link=>https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/

#solution
class Solution {
public int oddCells(int m, int n, int[][] indices) {
int[][] matrix=new int[m][n];
int row, col, count=0;
for(int k=0; k<indices.length; k++){
row=indices[k][0];
col=indices[k][1];

for(int i=0; i<n; i++){
matrix[row][i]++;
}
for(int j=0; j<m; j++){
matrix[j][col]++;
}

}

for(int i=0; i<matrix.length; i++){
for(int j=0; j<matrix[i].length; j++){
if(matrix[i][j]%2==1) count++;
}
}

return count;
}
}