Last active
December 8, 2017 17:36
-
-
Save han8909227/83bd59bba40031f8740242c060992199 to your computer and use it in GitHub Desktop.
Zero Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def zero_matrix(matrix): | |
"""Take a matrix m x n, if any val is zero set the entire row/column to zero""" | |
zero_loc = [] | |
for j in range(len(matrix)): | |
for i in range(len(matrix[0])): | |
if matrix[j][i] == 0: | |
zero_loc.push((j,i)) | |
for j, i in zero_loc: | |
matrix[j] = [0 for val in range(len(matrix[j])] | |
for row in matrix: | |
matrix[row][i] = 0 | |
return matrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment