-
Notifications
You must be signed in to change notification settings - Fork 64
/
Boolean Matrix.cpp
38 lines (32 loc) · 1017 Bytes
/
Boolean Matrix.cpp
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
// Boolean Matrix: https://practice.geeksforgeeks.org/problems/boolean-matrix-problem-1587115620/1#
void booleanMatrix(vector<vector<int> > &matrix)
{
// code here
int row = matrix.size();
int col = matrix[0].size();
bool arr_row[row]; fill(arr_row, arr_row+row, false);
bool arr_col[col]; fill(arr_col, arr_col+col, false);
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++){
if(matrix[i][j] == 1){
arr_row[i] = true;
arr_col[j] = true;
}
}
}
for(int i=0;i<row;i++){
if(arr_row[i]){
for(int j=0;j<col;j++){
matrix[i][j]= 1;
}
}
}
for(int i=0;i<col;i++){
if(arr_col[i]){
for(int j=0;j<row;j++){
matrix[j][i] = 1;
}
}
}
}