Set Matrix Zeroes
Given an m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.
Only zeros present in the original matrix trigger zeroing; zeros you write along the way do not. The function modifies matrix in place and returns nothing; the tests then print its rows, space-separated.
Example
1,1,1 1,0,1 1,1,1
1 0 1 0 0 0 1 0 1
- Input:
matrixis a grid of integers, all 1s except a single 0 at row 1, column 1 (counting from 0). - Which lines get wiped: each original zero at position condemns all of row and all of column . Here the set of zero rows is and of zero columns .
- Rule per cell: entry becomes 0 if or , otherwise it keeps its value. Row 1 becomes 0 0 0; column 1 zeroes the middle entry of rows 0 and 2; the four corners keep their 1s.
- Output: the same grid, changed in place, printed row by row as
1 0 1,0 0 0,1 0 1. - Notice that and come only from zeros present before any change. The new zeros in row 1 must not spread further, or the whole grid would collapse to 0. A grid with no zeros comes back untouched.
Constraints
- 1 <= m, n <= 200
- -2^31 <= matrix[i][j] <= 2^31 - 1