(int[] nums1, int[] nums2)
| 1 | class Solution { |
| 2 | public int[] intersection(int[] nums1, int[] nums2) { |
| 3 | var seen = new HashSet<Integer>(); |
| 4 | for (int n : nums1) |
| 5 | seen.add(n); |
| 6 | |
| 7 | var res = new HashSet<Integer>(); |
| 8 | for (int n : nums2) { |
| 9 | if (seen.contains(n)) { |
| 10 | res.add(n); |
| 11 | } |
| 12 | } |
| 13 | |
| 14 | return res.stream().mapToInt(Integer::intValue).toArray(); |
| 15 | } |
| 16 | } |