[leetcode349]Intersection of Two Arrays
阅读原文时间:2023年07月09日阅读:1

设计的很烂的一道题

List res = new ArrayList<>();
// int l1 = nums1.length;
// int l2 = nums2.length;
// int l = 0;
// while (l set = new HashSet<>();
for (int a :
nums1) {
set.add(a);
}
for (int i = 0; i < nums2.length; i++) { if (set.contains(nums2[i])) res.add(nums2[i]); } set = new HashSet<>(res);
int[] nums = new int[set.size()];
int i =0;
for (int a :
set) {
nums[i] = a;
i++;
}
return nums;