编程语言:java
class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
List<Integer> col = new ArrayList<>();
for(int i = 0;i < nums1.length;i++){
set1.add(nums1[i]);
}
for(int i = 0;i < nums2.length;i++){
set2.add(nums2[i]);
}
for(int k : set1){
for(int m : set2){
if(k == m){
col.add(k);
}
}
}
int coll[] = new int[col.size()];
for(int i = 0;i < col.size();i++){
coll[i] = col.get(i);
}
return coll;
}
}