Skip to content

Commit 004cce7

Browse files
Add files via upload
1 parent 34a22c5 commit 004cce7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 128ms 31.39%
2+
class Solution:
3+
def setZeroes(self, matrix):
4+
"""
5+
:type matrix: List[List[int]]
6+
:rtype: void Do not return anything, modify matrix in-place instead.
7+
"""
8+
m, n = len(matrix), len(matrix[0])
9+
if m is 0 or n is 0:
10+
return
11+
12+
first_row_zero = True if 0 in matrix[0] else False
13+
first_column_zero = True if 0 in [row[0] for row in matrix] else False
14+
15+
for i in range(1, m):
16+
for j in range(1, n):
17+
if matrix[i][j] is 0:
18+
matrix[0][j] = matrix[i][0] = 0
19+
20+
for i in range(1, m):
21+
for j in range(1, n):
22+
if matrix[0][j] is 0 or matrix[i][0] is 0:
23+
matrix[i][j] = 0
24+
25+
if first_row_zero is True:
26+
for j in range(n):
27+
matrix[0][j] = 0
28+
29+
if first_column_zero is True:
30+
for i in range(m):
31+
matrix[i][0] = 0

0 commit comments

Comments
 (0)