My python solution using O(n) extra space, O(mn) runtime. 403ms


  • 0
    W
    def setZeroes(self, matrix):
        columns = set()
        for i in xrange(0,len(matrix)):
            for j in xrange(0,len(matrix[0])):
                if matrix[i][j] == 0:
                    for c in xrange(0,len(matrix[0])):
                        if matrix[i][c] == 0:
                            columns.add(c)
                        else:
                            matrix[i][c] = 0
                    break
        for e in columns:
            for r in xrange(0,len(matrix)):
                matrix[r][e] = 0

Log in to reply
 

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