classSolution: defsetZeroes(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ ifnot matrix: return R, C = len(matrix), len(matrix[0]) # First pass: Set rows/cols to infinity when you encounter 0 for r, c in itertools.product(range(R), range(C)): if matrix[r][c] == 0: for i inrange(R): if i == r or matrix[i][c] == 0: continue matrix[i][c] = float('inf') for j inrange(C): if j == c or matrix[r][j] == 0: continue matrix[r][j] = float('inf') # Second pass: Replace all infinity with 0 for r, c in itertools.product(range(R), range(C)): if matrix[r][c] == float('inf'): matrix[r][c] = 0