forked from BabesGotByte/Coding_SkillSet_Topicwise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnswer7.cpp
More file actions
30 lines (29 loc) · 719 Bytes
/
Answer7.cpp
File metadata and controls
30 lines (29 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
int n=matrix.size();
int m=matrix[0].size();
int c1=1;
for(int i=0;i<n;i++){
if(matrix[i][0]==0){
c1=0;
}
for(int j=1;j<m;j++){
if(matrix[i][j]==0){
matrix[i][0]=0;
matrix[0][j]=0;
}
}
}
for(int i=n-1;i>=0;i--){
for(int j=m-1;j>=1;j--){
if(matrix[i][0]==0||matrix[0][j]==0){
matrix[i][j]=0;
}
}
if(c1==0){
matrix[i][0]=0;
}
}
}
};