We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 34a22c5 commit 004cce7Copy full SHA for 004cce7
Set Matrix Zeroes/Set_Matrix_Zeroes.py
@@ -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
21
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