MCPcopy Create free account
hub / github.com/VanjaRo/LeetCode / intersect

Function intersect

tasks/350.go:13–31  ·  view source on GitHub ↗
(nums1 []int, nums2 []int)

Source from the content-addressed store, hash-verified

11}
12
13func intersect(nums1 []int, nums2 []int) []int {
14 var ret []int
15 numMap := make(map[int]int)
16 for _, el := range nums1 {
17 numMap[el]++
18 }
19 for _, el := range nums2 {
20 if _, ok := numMap[el]; ok {
21 numMap[el]--
22 if numMap[el] == 0 {
23 delete(numMap, el)
24 }
25 ret = append(ret, el)
26 }
27
28 }
29
30 return ret
31}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected