73. Set Matrix Zeroes

https://leetcode.com/problems/set-matrix-zeroes/

solution

class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        n_row = len(matrix)
        n_col = len(matrix[0])

        zero_coor = []
        for i in range(n_row):
            for j in range(n_col):
                if matrix[i][j] == 0:
                    zero_coor.append([i, j])
        
        for (i, j) in zero_coor:
            matrix[i] = [0 for _ in range(n_col)]
            for x in range(n_row):
                matrix[x][j] = 0

时间复杂度:O() 空间复杂度:O()

Last updated