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

17 lines
250 B
Go

package leetcode
func intersection(nums1 []int, nums2 []int) []int {
m := map[int]bool{}
var res []int
for _, n := range nums1 {
m[n] = true
}
for _, n := range nums2 {
if m[n] {
delete(m, n)
res = append(res, n)
}
}
return res
}