-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCProblem73.py
More file actions
36 lines (29 loc) · 1.03 KB
/
LCProblem73.py
File metadata and controls
36 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
73. Set Matrix Zeroes
Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.
You must do it in place.
"""
# Passes - Beats 90% of Python3 users
# Medium Difficulty Problem
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
# get the row and column of every 0 in the n * m matrix
# and push it onto the list
tmpI = []
tmpJ = []
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if(matrix[i][j] == 0):
tmpI.append(i)
tmpJ.append(j)
# iterate over the rows found and set everything in the row to 0
for i in tmpI:
for j in range(len(matrix[i])):
matrix[i][j] = 0
# iterate over the columns found and set everything in the column to 0
for j in tmpJ:
for i in range(len(matrix)):
matrix[i][j] = 0