Problem :

https://leetcode.com/problems/set-matrix-zeroes/


My Solution :

class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
Y, X = len(matrix), len(matrix[0])
y0 = True if 0 in matrix[0] else False
x0 = True if 0 in [row[0] for row in matrix] else False

for y in range(1, Y):
for x in range(1, X):
if matrix[y][x] == 0:
matrix[y][0] = 0
matrix[0][x] = 0

for y in range(1, Y):
for x in range(1, X):
if 0 in (matrix[y][0], matrix[0][x]):
matrix[y][x] = 0

if y0:
for x in range(X):
matrix[0][x] = 0

if x0:
for y in range(Y):
matrix[y][0] = 0