very clear python solution


  • 0
    Y
        def setZeroes(self, matrix):
            
            n, m = len(matrix), len(matrix[0])
            
            row = set()
            col = set()
            for i in range(n):
                for j in range(m):
                    if matrix[i][j] == 0:
                        row.add(i)
                        col.add(j)
    
                        
            for i in row:
                for j in range(m):
                    matrix[i][j] = 0
                
            for j in col:
                for i in range(n):
                    matrix[i][j] = 0
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.