mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
@ -132,6 +132,23 @@ class Solution:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
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:
|
javaScript:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user