class Solution {
public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
List<Integer> res = new ArrayList<>();
Map<Integer,Integer> map = new HashMap<>();
for (int i : nums1) {
map.put(i, 1);
}
for (int i : nums2) {
Integer num = map.getOrDefault(i, 0);
map.put(i, num | 2);
}
for (int i : nums3) {
Integer num = map.getOrDefault(i, 0);
map.put(i, num | 4);
}
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
Integer value = entry.getValue();
if ((value &(value - 1)) != 0) res.add(entry.getKey());
}
return res;
}
}
class Solution {
public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
Set<Integer> set3 = new HashSet<>();
List<Integer> res = new ArrayList<>();
int[] num = new int[105];
for (int i = 0; i < 105; i++) {
if (i < nums1.length ) set1.add(nums1[i]);
if (i < nums2.length ) set2.add(nums2[i]);
if (i < nums3.length ) set3.add(nums3[i]);
}
for (Integer integer : set1) num[integer]++;
for (Integer integer : set2) num[integer]++;
for (Integer integer : set3) num[integer]++;
for (int i = 0; i <= 100; i++) {
if (num[i] >= 2) res.add(i);
}
return res;
}
}
标签:map,int,res,至少,num,2032,数组,integer,new
From: https://www.cnblogs.com/eiffelzero/p/17013856.html