#73

Set Matrix Zeroes

specialist · 670 · lc medium +30 · verified · 62.5% accepted · 17,005 likes · top 64%

play →

Description

For every cell in m x n integer matrix matrix that equals 0, set its entire row and column to 0. Perform the modification in-place.

Example 1:

Input: matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output: [[1,0,1],[0,0,0],[1,0,1]]

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]]

Code

1
2
3
4
5
6