Practice/Meta/Leetcode 73. Set Matrix Zeroes
CodingMust
You are given an m×n integer matrix. Your task is to modify the matrix in-place such that if any cell contains the value 0, then you must set all cells in that cell's entire row and entire column to 0.
The challenge is to accomplish this transformation while using only constant extra space. This means you cannot allocate additional arrays proportional to the size of the matrix (like O(m+n) or O(m×n) space).
m == matrix.lengthn == matrix[0].length1 <= m, n <= 200-2^31 <= matrix[i][j] <= 2^31 - 1Example 1:
Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0],[1,0,1]] Explanation: The zero at position (1,1) causes the entire second row and second column to become zeros.
Example 2:
Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]] Explanation: The zeros at (0,0) and (0,3) cause row 0 to be all zeros, and columns 0 and 3 to be zeros throughout.
Example 3:
Input: matrix = [[1,2,3],[4,5,6]] Output: [[1,2,3],[4,5,6]] Explanation: No zeros exist, so the matrix remains unchanged.