Skip to content

Commit aa84f42

Browse files
committed
[Add] Leetcode > 73. Set Matrix Zeroes
1 parent 831b624 commit aa84f42

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Leetcode/set_matrix_zeroes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 73. Set Matrix Zeroes
2+
3+
class Solution:
4+
def setZeroes(self, matrix: List[List[int]]) -> None:
5+
"""
6+
Do not return anything, modify matrix in-place instead.
7+
"""
8+
m = len(matrix)
9+
n = len(matrix[0])
10+
zero_arr = []
11+
12+
for i in range(m):
13+
for j in range(n):
14+
if matrix[i][j] == 0:
15+
zero_arr.append((i, j))
16+
17+
for (x, y) in zero_arr:
18+
for j in range(n):
19+
matrix[x][j] = 0
20+
for i in range(m):
21+
matrix[i][y] = 0

0 commit comments

Comments
 (0)