#1252
Cells with Odd Values in a Matrix
newbie · 250 · lc easy +18 · verified · 79.7% accepted · 1,335 likes · top 91%
Description
You have an m x n matrix of zeros and an operation list indices where each indices[i] = [ri, ci].
For each entry, perform both:
- Increment every element in row ri by 1.
- Increment every element in column ci by 1.
After processing all entries in indices, return the number of cells whose value is odd.
Example 1:
Input: m = 2, n = 3, indices = [[0,1],[1,1]]
Output: 6
Explanation: Initial matrix = [[0,0,0],[0,0,0]].
After applying first increment it becomes [[1,2,1],[0,1,0]].
The final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.
Example 2:
Input: m = 2, n = 2, indices = [[1,1],[0,0]]
Output: 0
Explanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.
Code
1
2
3