73. Set Matrix Zeroes Medium

@problem@discussion
#Array#Hash Table#Matrix



1/**
2 * [73] Set Matrix Zeroes
3 *
4 * Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.
5 * You must do it <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">in place</a>.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg" style="width: 450px; height: 169px;" />
9 * Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
10 * Output: [[1,0,1],[0,0,0],[1,0,1]]
11 * 
12 * Example 2:
13 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg" style="width: 450px; height: 137px;" />
14 * Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
15 * Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	m == matrix.length
21 * 	n == matrix[0].length
22 * 	1 <= m, n <= 200
23 * 	-2^31 <= matrix[i][j] <= 2^31 - 1
24 * 
25 *  
26 * Follow up:
27 * 
28 * 	A straightforward solution using O(mn) space is probably a bad idea.
29 * 	A simple improvement uses O(m + n) space, but still not the best solution.
30 * 	Could you devise a constant space solution?
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/set-matrix-zeroes/
36// discuss: https://leetcode.com/problems/set-matrix-zeroes/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn set_zeroes(matrix: &mut Vec<Vec<i32>>) {
42        
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_73() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.