Set Matrix Zeroes

Medium

Given an m × n integer matrix, return a matrix where every row and column containing a 0 is set to 0.

Example 1

setZeroes()
Input
matrix = [[1,1,1],[1,0,1],[1,1,1]]
Output
[[1,0,1],[0,0,0],[1,0,1]]

Example 2

setZeroes()
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]]
Constraints
1 <= m, n <= 200
-2^31 <= matrix[i][j] <= 2^31 - 1

Topics

ArraysMatrixHash Table

Implement setZeroes in the editor and return the answer — printing it is never graded.