MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / intersect

Function intersect

intersection_of_two_arrays_ii_350/solution.go:3–18  ·  view source on GitHub ↗
(nums1 []int, nums2 []int)

Source from the content-addressed store, hash-verified

1package intersection_of_two_arrays_ii_350
2
3func intersect(nums1 []int, nums2 []int) []int {
4 counts := make(map[int]int)
5 for _, n := range nums1 {
6 counts[n]++
7 }
8
9 res := make([]int, 0)
10 for _, n := range nums2 {
11 if v, ok := counts[n]; ok && v > 0 {
12 res = append(res, n)
13 counts[n]--
14 }
15 }
16
17 return res
18}

Callers 1

Test_intersectFunction · 0.85

Calls

no outgoing calls

Tested by 1

Test_intersectFunction · 0.68