File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,8 @@ class Solution:
231231
232232### Go:
233233
234+ (版本一)使用字典和集合
235+
234236``` go
235237func intersection (nums1 []int , nums2 []int ) []int {
236238 set := make (map [int ]struct {},0 ) // 用map模拟set
@@ -251,6 +253,28 @@ func intersection(nums1 []int, nums2 []int) []int {
251253}
252254```
253255
256+ (版本二)使用数组
257+
258+ ``` go
259+ func intersection (nums1 []int , nums2 []int ) []int {
260+ count1 := make ([]int , 1001 , 1001 )
261+ count2 := make ([]int , 1001 , 1001 )
262+ res := make ([]int , 0 )
263+ for _ , v := range nums1 {
264+ count1[v] = 1
265+ }
266+ for _ , v := range nums2 {
267+ count2[v] = 1
268+ }
269+ for i := 0 ; i <= 1000 ; i++ {
270+ if count1[i] + count2[i] == 2 {
271+ res = append (res, i)
272+ }
273+ }
274+ return res
275+ }
276+ ```
277+
254278### JavaScript:
255279
256280``` js
You can’t perform that action at this time.
0 commit comments