Skip to content

Commit 08dfd1d

Browse files
authored
Create 0349-intersection-of-two-arrays.java
1 parent ab7ac03 commit 08dfd1d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

0 commit comments

Comments
 (0)