diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index fe019a0a..090480a4 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -132,6 +132,23 @@ class Solution: Go: +```go +func intersection(nums1 []int, nums2 []int) []int { + m := make(map[int]int) + for _, v := range nums1 { + m[v] = 1 + } + var res []int + // 利用count>0,实现重复值只拿一次放入返回结果中 + for _, v := range nums2 { + if count, ok := m[v]; ok && count > 0 { + res = append(res, v) + m[v]-- + } + } + return res +} +``` javaScript: