classSolution(object):defsetZeroes(self,matrix):""" :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ifnotmatrix:returnfr=Falsefc=Falserow=len(matrix)col=len(matrix[0])# check first colforiinrange(row):ifmatrix[i][0]==0:fc=Truebreak# check first rowforiinrange(col):ifmatrix[0][i]==0:fr=Truebreak# use first row and col to store the status of other rows/colsforiinrange(1,row):forjinrange(1,col):ifmatrix[i][j]==0:matrix[i][0]=0matrix[0][j]=0# update row/col except first row/colforiinrange(1,row):ifmatrix[i][0]==0:forjinrange(1,col):matrix[i][j]=0foriinrange(1,col):ifmatrix[0][i]==0:forjinrange(1,row):matrix[j][i]=0# update the first row/coliffr:foriinrange(0,col):matrix[0][i]=0iffc:foriinrange(0,row):matrix[i][0]=0return