grid of size m × n. For every zero that was in the grid at the start, set its whole row and whole column to zero. Zeros created along the way do not spread any further.
Return the grid after the zeroing.
Try to use only O(1) extra memory.grid=[[5, 7, 2], [4, 0, 9], [8, 6, 3]] → [[5, 0, 2], [0, 0, 0], [8, 0, 3]]
The only zero sits in the centre, so the middle row and the middle column are cleared: [[5, 0, 2], [0, 0, 0], [8, 0, 3]].
grid=[[0, 3, 4, 1], [2, 8, 7, 0]] → [[0, 0, 0, 0], [0, 0, 0, 0]]
The zero in the first row clears that row and the first column, the zero in the second row clears that row and the last column. Both rows end up all zeros.
grid=[[1, 2], [3, 4]] → [[1, 2], [3, 4]]
There are no zeros, so the grid stays as it is.
m == grid.length, n == grid[i].lengthm, n ≤ 200grid[i][j] ≤ 2³¹ − 1grid=[[5, 7, 2], [4, 0, 9], [8, 6, 3]]
[[5, 0, 2], [0, 0, 0], [8, 0, 3]]
Run checks the first 3 tests in your browser. Submit checks all 35 tests on the server, hidden ones included.