Skip to content

Commit 5527467

Browse files
committed
73
1 parent 69f3355 commit 5527467

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

set-matrix-zeroes/jeldo.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
# Time: O(m*n), m = len(matrix), len(matrix[0])
3+
# Space: O(m+n)
4+
def setZeroes(self, matrix: list[list[int]]) -> None:
5+
"""
6+
Do not return anything, modify matrix in-place instead.
7+
"""
8+
row_zeros, col_zeros = set(), set()
9+
for i in range(len(matrix)):
10+
for j in range(len(matrix[0])):
11+
if matrix[i][j] == 0:
12+
row_zeros.add(i)
13+
col_zeros.add(j)
14+
for r in row_zeros:
15+
for j in range(len(matrix[0])):
16+
matrix[r][j] = 0
17+
for c in col_zeros:
18+
for i in range(len(matrix)):
19+
matrix[i][c] = 0

0 commit comments

Comments
 (0)