Created
August 28, 2017 13:43
-
-
Save luojiyin1987/5b27d7a0ca05af869079f53034a6a9ce to your computer and use it in GitHub Desktop.
Intersection of Two Arrays II
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func intersect(nums1 []int, nums2 []int) []int { | |
| temp1 := make(map[int]int) | |
| temp2 :=make(map[int]int) | |
| result := []int{} | |
| for _, v := range nums1 { | |
| temp1[v]++ | |
| } | |
| for _, v := range nums2 { | |
| temp2[v]++ | |
| } | |
| for k, value := range temp1{ | |
| _, ok2 := temp2[k] | |
| if ok2 { | |
| min := 0 | |
| if value < temp2[k] { | |
| min = value | |
| }else { | |
| min = temp2[k] | |
| } | |
| for i :=0 ; i < min ; i++ { | |
| result = append(result, k) | |
| } | |
| } | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment