class Solution {
public:
void setZeroes(vector<vector<int>>& matrix)
{
if(matrix.empty()|| matrix[0].empty())
return;
int m=matrix.size();
int n=matrix[0].size();
vector<bool> row(m,false);
vector<bool> column(n,false);
for(int i=0;i<m;++i)
for(int j=0;j<n;++j)
{
if(matrix[i][j]==0)
{
row[i]=true;
column[j]=true;
}
}
for(int i = 0; i < m; i ++)
{
for(int j = 0; j < n; j ++)
{
if(row[i] == true)
matrix[i][j] = 0;
if(column[j] == true)
matrix[i][j] = 0;
}
}
}
};
Set Matrix Zeroes
最新推荐文章于 2020-12-23 07:06:23 发布