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 e19e8c1 commit 5a40ebeCopy full SHA for 5a40ebe
set-matrix-zeroes/i-mprovising.py
@@ -0,0 +1,23 @@
1
+"""
2
+Time, space complexity O(m * n)
3
4
+
5
+class Solution:
6
+ def setZeroes(self, matrix: List[List[int]]) -> None:
7
+ """
8
+ Do not return anything, modify matrix in-place instead.
9
10
+ m, n = len(matrix), len(matrix[0])
11
+ i_indices = set()
12
+ j_indices = set()
13
+ for i in range(m):
14
+ for j in range(n):
15
+ if matrix[i][j] == 0:
16
+ i_indices.add(i)
17
+ j_indices.add(j)
18
19
+ for i in i_indices:
20
+ matrix[i] = [0 for _ in range(n)]
21
+ for j in j_indices:
22
23
+ matrix[i][j] = 0
0 commit comments