-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetMatrixOnes.java
More file actions
36 lines (32 loc) · 898 Bytes
/
setMatrixOnes.java
File metadata and controls
36 lines (32 loc) · 898 Bytes
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
import java.util.* ;
import java.io.*;
public class Solution
{
public static void setMatrixOnes(ArrayList<ArrayList<Integer>> MAT, int n, int m)
{
// Write your code here.
ArrayList<Integer> arr1 = new ArrayList<>();
ArrayList<Integer> arr2 = new ArrayList<>();
for(int i=0;i<n;i++){
arr1.add(i,0);
}
for(int i=0;i<m;i++){
arr2.add(i,0);
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(MAT.get(i).get(j)==1){
arr1.set(i, 1);
arr2.set(j, 1);
}
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(arr1.get(i)==1 || arr2.get(j)==1){
MAT.get(i).set(j, 1);
}
}
}
}
}