We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 28fb96a commit d0d3502Copy full SHA for d0d3502
set-matrix-zeroes/printjin-gmailcom.py
@@ -0,0 +1,23 @@
1
+class Solution:
2
+ def setZeroes(self, matrix):
3
+ first_row_zero = any(matrix[0][j] == 0 for j in range(len(matrix[0])))
4
+ first_col_zero = any(matrix[i][0] == 0 for i in range(len(matrix)))
5
+
6
+ for i in range(1, len(matrix)):
7
+ for j in range(1, len(matrix[0])):
8
+ if matrix[i][j] == 0:
9
+ matrix[i][0] = 0
10
+ matrix[0][j] = 0
11
12
13
14
+ if matrix[i][0] == 0 or matrix[0][j] == 0:
15
+ matrix[i][j] = 0
16
17
+ if first_row_zero:
18
+ for j in range(len(matrix[0])):
19
20
21
+ if first_col_zero:
22
+ for i in range(len(matrix)):
23
0 commit comments