Simple c++ solution using find


#1

void Solution::setZeroes(vector<vector > &A) {
int i,j;
vectorai;
vectorbi;
vector::iterator it1;
vector::iterator it2;
for(i=0;i<A.size();i++){
for(j=0;j<A[i].size();j++){
if(A[i][j]==0){
it1=find(ai.begin(),ai.end(),i);
if(it1==ai.end()){
ai.push_back(i);
}
it2=find(bi.begin(),bi.end(),j);
if(it2==bi.end()){
bi.push_back(j);
}
}
}
}
for(i=0;i<A.size();i++){
for(j=0;j<A[i].size();j++){
it1=find(ai.begin(),ai.end(),i);
it2=find(bi.begin(),bi.end(),j);
if(it1!=ai.end()||it2!=bi.end()){
A[i][j]=0;
}
}
}

}