-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob1386.java
47 lines (45 loc) · 1.45 KB
/
prob1386.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
41
42
43
44
45
46
47
class Solution {
public int maxNumberOfFamilies(int n, int[][] rs) {
int m=10;
int c=0;
HashMap<Integer,HashSet<Integer>>map=new HashMap<>();
for(int i=0;i<rs.length;i++){
int r=rs[i][0];
int col=rs[i][1];
if(!map.containsKey(r-1))
map.put(r-1,new HashSet<>());
map.get(r-1).add(col-1);
}
for(int i=0;i<n;i++){
HashSet<Integer>temp=new HashSet<>();
if(!map.containsKey(i)){
c+=2;
continue;
}
temp=map.get(i);
int a=1;
int idx2=1;
if(temp.contains(idx2) || temp.contains(idx2+1) || temp.contains(idx2+2) || temp.contains(idx2+3))
a=0;
c+=a;
if(a==1){
idx2=5;
if(temp.contains(idx2) || temp.contains(idx2+1) || temp.contains(idx2+2) || temp.contains(idx2+3))
c+=0;
else
c+=1;
}
else{
int bb=1,cc=1;
idx2=3;
if(temp.contains(idx2) || temp.contains(idx2+1) || temp.contains(idx2+2) || temp.contains(idx2+3))
bb=0;
idx2=5;
if(temp.contains(idx2) || temp.contains(idx2+1) || temp.contains(idx2+2) || temp.contains(idx2+3))
cc=0;
c+=Math.max(bb,cc);
}
}
return c;
}
}