1252. Cells with Odd Values in a Matrix
Last updated
Last updated
https://leetcode.com/problems/cells-with-odd-values-in-a-matrix
There is an m x n
matrix that is initialized to all 0
's. There is also a 2D array indices
where each indices[i] = [ri, ci]
represents a 0-indexed location to perform some increment operations on the matrix.
For each location indices[i]
, do both of the following:
Increment all the cells on row ri
.
Increment all the cells on column ci
.
Given m
, n
, and indices
, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices
.
Example 1:
Example 2:
Constraints:
1 <= m, n <= 50
1 <= indices.length <= 100
0 <= ri < m
0 <= ci < n
Follow up: Could you solve this in O(n + m + indices.length)
time with only O(n + m)
extra space?