2025-08-02 13:38:17 +0000 UTC

Cells with Odd Values in a Matrix

Code

class Solution:
    def oddCells(self, m: int, n: int, indices: List[List[int]]) -> int:
        mat = [[0] * n for _ in range(m)]
        for row, col in indices:
            for cur_col in range(n):
                mat[row][cur_col] += 1
            for cur_row in range(m):
                mat[cur_row][col] += 1
        count = 0
        for row in range(m):
            for col in range(n):
                if mat[row][col] % 2 != 0:
                    count += 1
        return count