Skip to content

Commit

Permalink
73
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeldo committed Jan 25, 2025
1 parent 69f3355 commit 5527467
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions set-matrix-zeroes/jeldo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution:
# Time: O(m*n), m = len(matrix), len(matrix[0])
# Space: O(m+n)
def setZeroes(self, matrix: list[list[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
row_zeros, col_zeros = set(), set()
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if matrix[i][j] == 0:
row_zeros.add(i)
col_zeros.add(j)
for r in row_zeros:
for j in range(len(matrix[0])):
matrix[r][j] = 0
for c in col_zeros:
for i in range(len(matrix)):
matrix[i][c] = 0

0 comments on commit 5527467

Please sign in to comment.