class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();
for(int num1 : nums1) {
set1.add(num1);
}
for(int num2 : nums2) {
set2.add(num2);
}
set1.retainAll(set2);//找出set2中和set1相同的数
//将集合里面的数转化为int类型 然后转化成集合
return set1.stream().mapToInt(i->i).toArray();
}
}
算法-二分法-两个数组的交集
猜你喜欢
转载自blog.csdn.net/qq_45100361/article/details/112649391
今日推荐
周排行