-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path73.py
32 lines (31 loc) · 820 Bytes
/
73.py
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
32
class Solution(object):
def setZeroes(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: None Do not return anything, modify matrix in-place instead.
"""
rows = []
cols = []
m = len(matrix)
n = len(matrix[0])
for i in range(m):
for j in range(n):
if matrix[i][j]==0:
rows.append(i)
cols.append(j)
rows = list(set(rows))
cols = list(set(cols))
for r in rows:
for k in range(n):
matrix[r][k]=0
for c in cols:
for k in range(m):
matrix[k][c]=0
return matrix
if __name__ == '__main__':
solution = Solution()
print solution.setZeroes([
[1,1,1],
[1,0,1],
[1,1,1]
])