class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
for (int i : nums1) {
set1.add(i);
}
for (int i : nums2) {
if (set1.contains(i)) {
set2.add(i);
}
}
return set2.stream().mapToInt(Integer::intValue).toArray();
}
}
class Solution {
public boolean isHappy(int n) {
Set<Integer> set1 = new HashSet<>();
boolean flag = true;
while (flag) {
n = sum(n);
if (n == 1) {
return flag;
}
flag = set1.add(n);
}
return flag;
}
public int sum(int n) {
int result = 0;
while (n > 0) {
int mod = n % 10;
result += mod * mod;
n /= 10;
}
return result;
}
}