# -*- coding:utf-8 -*- class Clearer: def clearZero(self, mat, n): # write code here row=[] colum=[] for i in range(n): for j in range(n): if mat[i][j]==0: row.append(i) colum.append(j) for i in range(n): for j in range(n): if i in row or j in colum: mat[i][j]=0 return mat
class Clearer { public: vector<vector<int> > clearZero(vector<vector<int> > mat, int n) { // write code here vector<int> row(n,0);//不加(n,0)会显示堆栈溢出 vector<int> col(n,0); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(mat[i][j]==0){ row[i]=1; col[j]=1; } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(row[i]==1 || col[j]==1) mat[i][j]=0; } } return mat; } };