-
Notifications
You must be signed in to change notification settings - Fork 0
/
Boolean Matrix
40 lines (33 loc) Β· 1015 Bytes
/
Boolean Matrix
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
39
40
class Solution
{
public:
//Function to modify the matrix such that if a matrix cell matrix[i][j]
//is 1 then all the cells in its ith row and jth column will become 1.
void cover(vector<vector<int> > &m, int row, int col){
for(int i = 0; i < m.size(); i++){
m[i][col] = 1;
}
for(int j = 0; j < m[0].size(); j++){
m[row][j] = 1;
}
}
void booleanMatrix(vector<vector<int> > &m)
{
// code here
int row = m.size();
int col = m[0].size();
vector<vector<int>> temp(row,vector<int>(col, 0));
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
if(m[i][j] == 1) temp[i][j] = 1;
}
}
for(int i = 0; i < row; i++){
for(int j = 0; j < col; j++){
if(temp[i][j] == 1){
cover(m,i,j);
}
}
}
}
};