Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 535 Bytes

1252.md

File metadata and controls

20 lines (18 loc) · 535 Bytes

1252. Cells with Odd Values in a Matrix

Solution 1 (time O(m*n), space O(m+n))

class Solution(object):
    def oddCells(self, m, n, indices):
        """
        :type m: int
        :type n: int
        :type indices: List[List[int]]
        :rtype: int
        """
        r = [0 for _ in range(m)]
        c = [0 for _ in range(n)]
        for cur_r, cur_c in indices:
            r[cur_r] += 1
            c[cur_c] += 1
        return sum((cur_r + cur_c) % 2 for cur_r in r for cur_c in c)