Problem: 73. 矩阵置零
思路 & 解题方法
二维数组简单使用。
复杂度
时间复杂度:
添加时间复杂度, 示例: O ( n m ) O(nm) O(nm)
空间复杂度:
添加空间复杂度, 示例: O ( n m ) O(nm) O(nm)
Code
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])
raw = []
cow = []
for i in range(m):
for j in range(n):
if matrix[i][j] == 0:
raw.append(i)
cow.append(j)
for r in raw:
for j in range(n):
matrix[r][j] = 0
for c in cow:
for i in range(m):
matrix[i][c] = 0