class Solution {
public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
List<Integer> res = new ArrayList<>();
Map<Integer, Integer> map = new HashMap<>();
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
Set<Integer> set3 = new HashSet<>();
for (int n : nums1) {
set1.add(n);
}
for (int n : nums2) {
set2.add(n);
}
for (int n : nums3) {
set3.add(n);
}
for (int n : set1) {
map.put(n, 1);
}
for (int n : set2) {
map.put(n, map.getOrDefault(n, 0)+1);
}
for (int n : set3) {
map.put(n, map.getOrDefault(n, 0)+1);
}
map.forEach((key, value) ->{
if (value >= 2) {
res.add(key);
}
});
return res;
}
}
/*
set
map
1 1
2 1
4 1
3 1
5 1
[3,1], nums2 = [2,3], nums3 = [1,2]
3 2
2 2
1 2
nums1 = [1,1,3,2], nums2 = [2,3], nums3 = [3]
3 3
2 2
1
1 1
2 1
4 1
3
*/