1.7数组 清除行列

 1 class Clearer {
 2 public:
 3     vector<vector<int> > clearZero(vector<vector<int> > mat, int n) {
 4         // write code here
 5         int nrow=mat.size();
 6         int ncolumn=mat[0].size();
 7         bool *row=new bool[nrow]();
 8         bool *column=new bool[ncolumn]();
 9         //记录值为0的元素所在行索引和列索引
10         for(int i=0;i<nrow;i++)
11         {
12             for(int j=0;j<ncolumn;j++)
13             {
14                 if(mat[i][j]==0)
15                 {
16                     row[i]=true;
17                     column[j]=true;
18                 }
19             }
20         }
21         //若行i或列j有个元素为0,则将arr[i][j]置为0
22         for(int i=0;i<nrow;i++)
23         {
24             for(int j=0;j<ncolumn;j++)
25             {
26                 if(row[i]||column[j])
27                     mat[i][j]=0;
28             }
29         }
30         return mat;
31     }
32 };
原文地址:https://www.cnblogs.com/hslzju/p/5704195.html