Set Matrix Zeroes
Given an m x n integer matrix, if any cell is 0 set its entire row and entire column to 0. Do it in place, using O(1) extra space (no separate m+n marker arrays).
Open official problem prompt ↗Blank out every row and column that touches a zero, changing the grid directly without proportional extra memory.
Like using the margins of a spreadsheet to jot which rows and columns to erase, instead of grabbing a separate notepad.
- Input
- matrix = [[1,1,1],[1,0,1],[1,1,1]]
- Output
- [[1,0,1],[0,0,0],[1,0,1]]
- Why
- The single 0 sits at row 1, column 1, so that whole row and column become 0 while the rest is unchanged.
m == matrix.lengthn == matrix[0].length1 <= m, n <= 200-2^31 <= matrix[i][j] <= 2^31 - 1