Skip to content

Commit cb476d7

Browse files
Create Set Matrix Zero
1 parent 0d72884 commit cb476d7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2D Arrays/Set Matrix Zero.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
void setZeroes(vector<vector<int>>& m) {
4+
set<int>row,col;
5+
6+
for(int i=0;i<m.size();i++){
7+
for(int j=0;j<m[0].size();j++){
8+
if(m[i][j]==0){
9+
row.insert(i);
10+
col.insert(j);
11+
}
12+
}
13+
}
14+
15+
16+
for(auto it=row.begin();it!=row.end();it++){
17+
for(int j=0;j<m[0].size();j++){
18+
m[*it][j]=0;
19+
}
20+
21+
}
22+
for(auto it=col.begin();it!=col.end();it++){
23+
for(int j=0;j<m.size();j++){
24+
m[j][*it]=0;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)