-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ73.py
More file actions
31 lines (30 loc) · 871 Bytes
/
Q73.py
File metadata and controls
31 lines (30 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import List
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
zeroRows = set()
zeroColumns = set()
m = len(matrix)
n = len(matrix[0])
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if matrix[i][j]:
continue
else:
zeroRows.add(i)
zeroColumns.add(j)
for val in zeroRows:
matrix[val][:] = [0]*n
for val in zeroColumns:
for k in range(m):
matrix[k][val] = 0
if __name__ == '__main__':
matrix = [
[1,1,1],
[1,0,1],
[1,1,1]
]
Solution().setZeroes(matrix)
print(matrix)