Set Matrix Zeroes
For every zero in the original matrix, set its entire row and column to zero in place. Newly written zeros do not trigger more changes. Return nothing; aim for constant auxiliary space.
Example 1
0,01
0,12
0,23
1,04
1,10
1,26
2,07
2,18
2,29
matrix = [[1,2,3],[4,0,6],[7,8,9]][[1,0,3],[0,0,0],[7,0,9]]Explanation
The original zero clears row 1 and column 1; other corners stay unchanged.
Example 2
0,00
0,11
1,02
1,13
matrix = [[0,1],[2,3]][[0,0],[0,3]]Explanation
The top-left zero clears row 0 and column 0, leaving 3.
Example 3
0,01
matrix = [[1]][[1]]Explanation
No original zero means no change.
Constraints
- 1 <= rows,columns <= 200
- Entries are signed 32-bit integers
Function contract
setZeroesArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,2,3],[4,0,6],[7,8,9]]