MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / intersection

Method intersection

java/0349-intersection-of-two-arrays.java:2–15  ·  view source on GitHub ↗
(int[] nums1, int[] nums2)

Source from the content-addressed store, hash-verified

1class 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}

Callers

nothing calls this directly

Calls 2

addMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected