Skip to content

Commit fcef7c2

Browse files
committed
Time: 101 ms (67.41%), Space: 17.5 MB (78.22%) - LeetHub
1 parent dff9845 commit fcef7c2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# time complexity: O(m*n)
2+
# space complexity: O(m+n)
3+
from typing import List
4+
5+
6+
class Solution:
7+
def setZeroes(self, matrix: List[List[int]]) -> None:
8+
rowSet, colSet = set(), set()
9+
for i in range(len(matrix)):
10+
for j in range(len(matrix[0])):
11+
if matrix[i][j] == 0:
12+
rowSet.add(i)
13+
colSet.add(j)
14+
for i in range(len(matrix)):
15+
for j in range(len(matrix[0])):
16+
if i in rowSet or j in colSet:
17+
matrix[i][j] = 0
18+
return matrix
19+
20+
21+
matrix = [[0, 1, 2, 0], [3, 4, 5, 2], [1, 3, 1, 5]]
22+
print(Solution().setZeroes(matrix))

0 commit comments

Comments
 (0)