forked from pujazha/Hactoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoolean Matrix
34 lines (28 loc) · 797 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
//User function Template for Java
class Solution
{
//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 booleanMatrix(int matrix[][])
{
// code here
int n = matrix.length, m = matrix[0].length;
int row[] = new int[n];
int col[] = new int[m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(matrix[i][j]==1){
row[i]=1;
col[j]=1;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(row[i]==1 || col[j]==1){
matrix[i][j]=1;
}
}
}
}
}