# 矩阵置零

给定一个 m x n 的矩阵,如果一个元素为 0 ,则将其所在行和列的所有元素都设为 0 。请使用 原地 算法

进阶:

 

示例 1:

输入:matrix = [[1,1,1],[1,0,1],[1,1,1]]
输出:
[[1,0,1],[0,0,0],[1,0,1]]

示例 2:

输入:matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]]
输出:
[[0,0,0,0],[0,4,5,0],[0,3,1,0]]

 

提示:

## template ```python class Solution(object): def setZeroes(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ if not matrix: return m = len(matrix) if m == 0: return r = [] c = [] n = len(matrix[0]) for i in range(m): for j in range(n): if matrix[i][j] == 0: r.append(i) c.append(j) r = set(r) c = set(c) for i in r: for j in range(n): matrix[i][j] = 0 for i in range(m): for j in c: matrix[i][j] = 0 return matrix # %% s = Solution() print(s.setZeroes(matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]])) ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```