Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 98a80fc

Browse files
authored
Create Day-13_Set_Matrix_Zeroes.py
1 parent 5c0e9ec commit 98a80fc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def setZeroes(self, matrix: List[List[int]]) -> None:
3+
"""
4+
Do not return anything, modify matrix in-place instead.
5+
"""
6+
rows = len(matrix)
7+
cols = len(matrix[0])
8+
cr = set()
9+
cs = set()
10+
for i in range(rows):
11+
for j in range(cols):
12+
if matrix[i][j] == 0:
13+
#matrix[i][0], matrix[0][j] = 0,0
14+
cs.add(j)
15+
cr.add(i)
16+
17+
for i in cr:
18+
matrix[i] = [0] * cols
19+
#print(matrix)
20+
for j in cs:
21+
for i in range(rows):
22+
matrix[i][j] = 0
23+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /