Skip to content

Commit

Permalink
Update set_matrix_zeroes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Abrar-Mustakim authored Jan 30, 2024
1 parent cc5f00f commit 1cdfec7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions set_matrix_zeroes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,42 @@ def setZeroes(self, matrix: List[List[int]]) -> None:
matrix[i][j] = 0

return matrix


#2nd Method
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
m = [0] * len(matrix)
n = [0] * len(matrix[0])
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if matrix[i][j] == 0:
m[i] = 1
n[j] = 1
for i in range(len(m)):
for j in range(len(n)):
if m[i] or n[j]:
matrix[i][j] = 0
return matrix



















0 comments on commit 1cdfec7

Please sign in to comment.