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 69f3355 commit 5527467Copy full SHA for 5527467
set-matrix-zeroes/jeldo.py
@@ -0,0 +1,19 @@
1
+class Solution:
2
+ # Time: O(m*n), m = len(matrix), len(matrix[0])
3
+ # Space: O(m+n)
4
+ def setZeroes(self, matrix: list[list[int]]) -> None:
5
+ """
6
+ Do not return anything, modify matrix in-place instead.
7
8
+ row_zeros, col_zeros = set(), set()
9
+ for i in range(len(matrix)):
10
+ for j in range(len(matrix[0])):
11
+ if matrix[i][j] == 0:
12
+ row_zeros.add(i)
13
+ col_zeros.add(j)
14
+ for r in row_zeros:
15
16
+ matrix[r][j] = 0
17
+ for c in col_zeros:
18
19
+ matrix[i][c] = 0
0 commit comments