-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setmatrixzeroes
38 lines (34 loc) · 903 Bytes
/
Setmatrixzeroes
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
30
31
32
33
34
35
36
37
38
class Solution {
public:
void setZeroes(vector<vector<int>>& m) {
int r=m.size();
int c=m[0].size();
vector<int> row;
vector<int> col;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(m[i][j]==0)
{
for(int k=0;k<c;k++)
{
if(m[i][k]!=0)
m[i][k]=INT_MIN-1;
}
for(int k=0;k<r;k++)
{
if(m[k][j]!=0)
m[k][j]=INT_MIN-1;
}
}
}
}
for(int i = 0; i < r ; i++){
for(int j = 0; j < c ; j++){
if(m[i][j]==INT_MIN-1)
m[i][j]=0;
}
}
}
};