(nums1 []int, nums2 []int)
| 1 | package intersection_of_two_arrays_ii_350 |
| 2 | |
| 3 | func 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 | } |
no outgoing calls