Problem:
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
Answer:
class Solution(object):
def setZeroes(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
tag_x = []
tag_y = []
for i in range(len(matrix)):
for j in range(len(matrix[i])):
if matrix[i][j] == 0:
tag_x.append(i)
tag_y.append(j)
for i in range(len(matrix)):
if i in tag_x :
matrix[i] = [0 for m in range(len(matrix[i]))]
for j in range(len(matrix[0])):
if j in tag_y:
for i in range(len(matrix)):
matrix[i][j] = 0