C++ Simple Easy Solution minimal code


#1

void Solution::setZeroes(vector<vector > &A) {
int n = A.size();
int m = A[0].size();
int i,j;
vector rows(n,0),cols(m,0);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(A[i][j]==0)
{
rows[i]++;
cols[j]++;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(rows[i]>=1||cols[j]>=1)
A[i][j]=0;
}
}
}