HELP! Question about 2d list in python


  • 0
    T

    I tried use the following code to set the ith row to be zeros.

    # zeroRow is a list to record whether ith row has zeros. 
    # e.g. zeroRow = [True, True, False] means 0th and 1st row have 0s and 2nd row don't have
    for i in range(m):
                if zeroRow[i]:
                    matrix[i]= [0 for i in range(n)]
    

    But it doesn't work sometime.
    For example:

    input :   [[1, 2, 3], [3, 0, 5], [2, 5, 0]]
    output: [[1, 2, 3], [3, 0, 5], [0, 0, 0]]
    
    

    Thanks


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.