class Solution: # @param matrix, a list of lists of integers # RETURN NOTHING, MODIFY matrix IN PLACE. def setZeroes(self, matrix): m=len(matrix) if m==0: return None n=len(matrix[0]) first_0_row,first_0_col=False,False if matrix[0].count(0)>0: first_0_row=True for i in range(m): if matrix[i][0]==0: first_0_col=True break for i in range(1,m): for j in range(1,n): if matrix[i][j]==0: matrix[0][j]=0 matrix[i][0]=0 for i in range(1,m): if matrix[i][0]==0: for j in range(1,n): matrix[i][j]=0 for j in range(1,n): if matrix[0][j]==0: for i in range(1,m): matrix[i][j]=0 if first_0_row: for i in range(n): matrix[0][i]=0 if first_0_col: for j in range(m): matrix[j][0]=0
Tuesday, September 9, 2014
Leetcode: Set Matrix Zeroes @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment