Skip to content

Commit 5a40ebe

Browse files
committed
add set-matrix-zeroes
1 parent e19e8c1 commit 5a40ebe

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

set-matrix-zeroes/i-mprovising.py

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

0 commit comments

Comments
 (0)