1252. Cells with Odd Values in a Matrix Easy

@problem@discussion
#Array#Math#Simulation



1/**
2 * [1252] Cells with Odd Values in a Matrix
3 *
4 * 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.
5 * For each location indices[i], do both of the following:
6 * <ol>
7 * 	Increment all the cells on row ri.
8 * 	Increment all the cells on column ci.
9 * </ol>
10 * Given m, n, and indices, return the number of odd-valued cells in the matrix after applying the increment to all locations in indices.
11 *  
12 * Example 1:
13 * <img alt="" src="https://assets.leetcode.com/uploads/2019/10/30/e1.png" style="width: 600px; height: 118px;" />
14 * Input: m = 2, n = 3, indices = [[0,1],[1,1]]
15 * Output: 6
16 * Explanation: Initial matrix = [[0,0,0],[0,0,0]].
17 * After applying first increment it becomes [[1,2,1],[0,1,0]].
18 * The final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.
19 * 
20 * Example 2:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2019/10/30/e2.png" style="width: 600px; height: 150px;" />
22 * Input: m = 2, n = 2, indices = [[1,1],[0,0]]
23 * Output: 0
24 * Explanation: Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= m, n <= 50
30 * 	1 <= indices.length <= 100
31 * 	0 <= ri < m
32 * 	0 <= ci < n
33 * 
34 *  
35 * Follow up: Could you solve this in O(n + m + indices.length) time with only O(n + m) extra space?
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/
41// discuss: https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn odd_cells(m: i32, n: i32, indices: Vec<Vec<i32>>) -> i32 {
47        0
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_1252() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.