Skip to content

Commit 96a73d4

Browse files
progress...
1 parent f6a5df8 commit 96a73d4

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+
"""
2+
Zero Matrix: Write an algorithm such that if an element in an MxN matrix is 0,
3+
its entire row and column are set to 0.
4+
Hints:#17, #74, #702
5+
"""
6+
7+
8+
9+
def zeroMatrix(matrix):
10+
m = len(matrix) - 1
11+
n = len(matrix[0]) - 1
12+
for i in range(m):
13+
for j in range(n):
14+
if matrix[i][j] == 0:
15+
matrix[i+1][j] = 0
16+
17+
18+
matrix = [[0,1,2],[3,4,5],[6,7,8]]
19+
20+
21+
zeroMatrix(matrix)
22+
print(matrix)

0 commit comments

Comments
 (0)