#NEWLINE# def setZeroes( self , matrix ) : #NEWLINE# #INDENT# '\n        store the zero at the head\n        constant space\n        :param matrix: a list of lists of integers\n        :return: NOTHING, MODIFY matrix IN PLACE.\n        ' #NEWLINE# if ( not matrix ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# m = len ( matrix ) #NEWLINE# n = len ( matrix [ 0 ] ) #NEWLINE# clear_first_row = False #NEWLINE# clear_first_col = False #NEWLINE# for row in xrange ( m ) : #NEWLINE# #INDENT# if ( matrix [ row ] [ 0 ] == 0 ) : #NEWLINE# #INDENT# clear_first_col = True #NEWLINE# #UNINDENT# #UNINDENT# for col in xrange ( n ) : #NEWLINE# #INDENT# if ( matrix [ 0 ] [ col ] == 0 ) : #NEWLINE# #INDENT# clear_first_row = True #NEWLINE# #UNINDENT# #UNINDENT# for row in xrange ( 1 , m ) : #NEWLINE# #INDENT# for col in xrange ( 1 , n ) : #NEWLINE# #INDENT# if ( matrix [ row ] [ col ] == 0 ) : #NEWLINE# #INDENT# matrix [ 0 ] [ col ] = 0 #NEWLINE# matrix [ row ] [ 0 ] = 0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for row in xrange ( 1 , m ) : #NEWLINE# #INDENT# if ( matrix [ row ] [ 0 ] == 0 ) : #NEWLINE# #INDENT# for col in xrange ( n ) : #NEWLINE# #INDENT# matrix [ row ] [ col ] = 0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for col in xrange ( 1 , n ) : #NEWLINE# #INDENT# if ( matrix [ 0 ] [ col ] == 0 ) : #NEWLINE# #INDENT# for row in xrange ( m ) : #NEWLINE# #INDENT# matrix [ row ] [ col ] = 0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if clear_first_row : #NEWLINE# #INDENT# for col in xrange ( n ) : #NEWLINE# #INDENT# matrix [ 0 ] [ col ] = 0 #NEWLINE# #UNINDENT# #UNINDENT# if clear_first_col : #NEWLINE# #INDENT# for row in xrange ( m ) : #NEWLINE# #INDENT# matrix [ row ] [ 0 ] = 0