Skip to content

Commit 2b712d7

Browse files
committed
set matrix zeroes solution
1 parent 8e8ce1c commit 2b712d7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

set-matrix-zeroes/devyejin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List
2+
class Solution:
3+
def setZeroes(self, matrix: List[List[int]]) -> None:
4+
"""
5+
Do not return anything, modify matrix in-place instead.
6+
"""
7+
n, m = len(matrix), len(matrix[0])
8+
rows, cols = set(), set()
9+
10+
for r in range(n):
11+
for c in range(m):
12+
if matrix[r][c] == 0:
13+
rows.add(r)
14+
cols.add(c)
15+
16+
for r in range(n):
17+
for c in range(m):
18+
if r in rows or c in cols:
19+
matrix[r][c] = 0
20+

0 commit comments

Comments
 (0)