73. Set Matrix Zeroes

class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
hashrow_=set()
hashcol_=set()
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if matrix[i][j]==0:
hashrow_.add(i)
hashcol_.add(j)
for i in range(len(matrix)):
for j in range(len(matrix[0])):
if(i in hashrow_):
matrix[i][j]=0
if(j in hashcol_):
matrix[i][j]=0
return matrix
class Solution:
def setZeroes(self, matrix: List[List[int]]) -> None:
first_row, first_col=0,0
for j in range(len(matrix[0])):
if(matrix[0][j]==0):
first_row=1
break
for i in range(len(matrix)):
if(matrix[i][0]==0):
print(i)
first_col=1
break
for i in range(1,len(matrix)):
for j in range(1,len(matrix[0])):
if(matrix[i][j]==0):
matrix[0][j]=0

for i in range(1,len(matrix)):
for j in range(1,len(matrix[0])):
if(matrix[0][j]==0):
matrix[i][j]=0
if(matrix[i][0]==0):
matrix[i][j]=0
if(first_row):
for j in range(len(matrix[0])):
matrix[0][j]=0
if(first_col):
for i in range(len(matrix)):
matrix[i][0]=0
return(matrix)

--

--

--

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Trias Project Weekly (Nov 11, 2019 — Nov 17, 2019)

Unity Package Manager 2020.1 Round-up

How to Django with MongoDB — The power of Djongo

Latest Trends For Web Development 2018

THINKIUM DEVELOPMENT SYSTEM

A sensible tech stack for apps

The Roadmap — The journey has just begun

Maximum yield with minimum expense for a static website

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

More from Medium

CS373 Spring 2022: Audie Bethea

CS373 Spring 2022: Anthony Modica

SingleStore JDBC Connection

Hi-Vibing Suzy