Python solution & beats 98%


  • 0
    D
        def setZeroes(self, matrix):
            """
            :type matrix: List[List[int]]
            :rtype: void Do not return anything, modify matrix in-place instead.
            """
            cols = []
            wid = len(matrix[0])
            height = len(matrix)
            for i in range(height):
                if 0 in matrix[i]:
                    cols += [ind for ind in range(wid) if matrix[i][ind] == 0]
                    matrix[i][:] = [0] * wid
            cols = list(set(cols))
            matrix[:] = zip(*matrix)
            for col in cols:
                matrix[col] = [0] * height
            matrix[:] = zip(*matrix)
            matrix[:] = map(lambda x: list(x), matrix)
    

Log in to reply
 

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