思路:
設置一個行的矩陣,和列的矩陣,保存元素爲0的行號和列號
如果行號或者列號被標記,賦值爲0
class Clearer {
public:
vector<vector<int> > clearZero(vector<vector<int> > mat, int n) {
int row[n]; //hang
int colum[n]; //lie
for(int i=0; i<n; i++)
row[i] = colum[i] = 0;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if(mat[i][j]==0)
{
row[i] = 1;
colum[j] = 1;
}
}
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if( (row[i]==1)||(colum[j]==1) )
mat[i][j]=0;
}
return mat;
}
};