Skip to content

Commit a080c5a

Browse files
committed
wordwrap comments attempt
1 parent cbe1e32 commit a080c5a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Python/chapter01/1.8 - Zero Matrix/miguel_1.8_sol.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
"""
22
Python version 3.7.0
33
1.8 - Zero Matrix
4-
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0
4+
Write an algorithm such that if an element in an MxN matrix is 0,
5+
its entire row and column are set to 0
56
"""
67
import unittest
78
from typing import List
89

910

1011
def zero_matrix(matrix: List[List[int]]) -> List[List[int]]:
1112
"""
12-
zero_matrix will take in an MxN matrix and when a 0 element is found, the whole column and row
13-
will be set to 0. The algorithm works by first scanning for rows and columns where there is a 0
14-
and store into a set.
15-
Then we go through each stored row and column indices and proceed to set the rows and columns to 0.
13+
zero_matrix will take in an MxN matrix and when a 0 element is found,
14+
the whole column and row will be set to 0.
15+
The algorithm works by first scanning for
16+
rows and columns where there is a 0 and store into a set.
17+
Then we go through each stored row and column indices
18+
and proceed to set the rows and columns to 0.
1619
Runtime: O(M * N)
1720
Space Complexity: O(M + N)
1821
:param matrix: an MxN matrix. M is the number of rows, N is the number of columns

0 commit comments

Comments
 (0)