阅读量:7
easy
使用两个数组shuax,shuay分别记录为0的i和j下标
然后两个for循环分别对行,列刷一次就可以了,虽然这样很浪费内存并且复杂度有点高,但能过就行。
class Solution: def setZeroes(self, matrix: List[List[int]]) -> None: """ Do not return anything, modify matrix in-place instead. """ m=len(matrix) n=len(matrix[0]) shuax=[] shuay=[] for i in range(m): for j in range(n): if matrix[i][j]==0: shuax.append(i) shuay.append(j) for i in range(m): if i in shuax: for j in range(n): matrix[i][j]=0 for j in range(n): if j in shuay: for i in range(m): matrix[i][j]=0