Question: https://oj.leetcode.com/problems/set-matrix-zeroes/
Question Name: Set Matrix Zeroes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class Solution: # @param matrix, a list of lists of integers # RETURN NOTHING, MODIFY matrix IN PLACE. def setZeroes(self, matrix): # Empty matrix if len(matrix) == 0 or len(matrix[0]) == 0: return row = [False] * len(matrix) column = [False] * len(matrix[0]) # Record the rows and columns with element(s) being zero. for rowIndex in xrange(len(matrix)): for colIndex in xrange(len(matrix[0])): if matrix[rowIndex][colIndex] == 0: row[rowIndex] = True column[colIndex] = True # Set the qualified entire row(s) and column(s) to zero. for rowIndex in xrange(len(matrix)): for colIndex in xrange(len(matrix[0])): if row[rowIndex] == True or column[colIndex] == True: matrix[rowIndex][colIndex] = 0 return |