Input:
[
[1,1,1],
[1,0,1],
[1,1,1]
]
Output:
[
[1,0,1],
[0,0,0],
[1,0,1]
]
Input:
[
[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]
]
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
idxs = {}
for r, row in enumerate(matrix):
for c, col in enumerate(row):
if col == 0: idxs[(r, c)] = 0
for idx_r, idx_c in idxs.keys():
for c in range(len(matrix[0])): matrix[idx_r][c] = 0
for r in range(len(matrix)): matrix[r][idx_c] = 0