-
Notifications
You must be signed in to change notification settings - Fork 0
/
leetcode1452_FavouriteCompanies.java
55 lines (45 loc) · 1.63 KB
/
leetcode1452_FavouriteCompanies.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
48
49
50
51
52
53
54
55
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class leetcode1452_FavouriteCompanies {
public List<Integer> peopleIndexes(List<List<String>> favoriteCompanies) {
boolean found =false;
String str;
int size_i, size_j, listSize = 0;
List<Integer> indices = new ArrayList<>();
List<Set<String>> set = new ArrayList<>();
for(List<String> fav: favoriteCompanies) {
set.add(new HashSet<>(fav));
}
listSize = favoriteCompanies.size();
for(int i=0;i<listSize;i++) {
found =false;
for(int j=0; j<listSize;j++) {
size_i = set.get(i).size();
size_j = set.get(j).size();
if(i != j && size_j >= size_i) {
if(set.get(j).containsAll(set.get(i))) {
found = true;
break;
}
}
}
if(found == false)
indices.add(i);
}
System.out.println(indices);
return indices;
}
public static void main(String[] args) {
leetcode1452_FavouriteCompanies obj = new leetcode1452_FavouriteCompanies();
List<List<String>> list = new ArrayList<>();
list.add(0, Arrays.asList("leetcode","google","facebook"));
list.add(1, Arrays.asList("google","microsoft"));
list.add(2, Arrays.asList("google","facebook"));
list.add(3, Arrays.asList("google"));
list.add(4, Arrays.asList("amazon"));
obj.peopleIndexes(list);
}
}