Files
LeetCode-Go/leetcode/0350.Intersection-of-Two-Arrays-II/350. Intersection of Two Arrays II.go
2020-08-07 17:06:53 +08:00

17 lines
239 B
Go

package leetcode
func intersect(nums1 []int, nums2 []int) []int {
m := map[int]int{}
var res []int
for _, n := range nums1 {
m[n]++
}
for _, n := range nums2 {
if m[n] > 0 {
res = append(res, n)
m[n]--
}
}
return res
}