forked from Ritikraja07/Java-problem-Open-Source
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Boolean_matrix.java
40 lines (39 loc) · 1.03 KB
/
Boolean_matrix.java
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
/*
Boolean Matrix
Link Of Problem - https://practice.geeksforgeeks.org/problems/boolean-matrix-problem-1587115620/1
*/
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 R = matrix.length;
int C = matrix[0].length;
boolean row[] = new boolean[R];
boolean col[] = new boolean[C];
int i ,j ;
for(i=0;i<R;i++){
row[i] = false;
}
for( i=0;i<C;i++){
col[i] = false;
}
for( i=0;i<R;i++){
for( j=0;j<C;j++){
if(matrix[i][j]==1){
row[i] = true;
col[j] = true;
}
}
}
for( i=0;i<R;i++){
for( j=0;j<C;j++){
if(row[i]==true || col[j]==true){
matrix[i][j] = 1;
}
}
}
}
}