Skip to content

Commit 9d4e348

Browse files
Create 0073M. Set Matrix Zeroes.py
1 parent 2dc82d8 commit 9d4e348

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

0073M. Set Matrix Zeroes.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Runtime: 112 ms, faster than 99.88% of Python3 online submissions for Set Matrix Zeroes.
2+
#Memory Usage: 15 MB, less than 91.08% of Python3 online submissions for Set Matrix Zeroes.
3+
4+
class Solution:
5+
def setZeroes(self, matrix: List[List[int]]) -> None:
6+
"""
7+
Do not return anything, modify matrix in-place instead.
8+
"""
9+
index_i = set()
10+
index_j = set()
11+
for i in range(len(matrix)):
12+
for j in range(len(matrix[0])):
13+
if matrix[i][j] == 0:
14+
index_i.add(i)
15+
index_j.add(j)
16+
for i in range(len(matrix)):
17+
for j in range(len(matrix[0])):
18+
if i in index_i or j in index_j:
19+
matrix[i][j] = 0
20+
return matrix

0 commit comments

Comments
 (0)