Skip to content

Instantly share code, notes, and snippets.

@mumunuu
Created January 13, 2021 06:00
Show Gist options
  • Save mumunuu/aeba522948071fed5246a2991e24e00e to your computer and use it in GitHub Desktop.
Save mumunuu/aeba522948071fed5246a2991e24e00e to your computer and use it in GitHub Desktop.
algorithm(leetcode) Intersection of Two Arrays II
func intersect(nums1 []int, nums2 []int) []int {
answer := make([]int, 0)
for _, v1 := range nums1 {
for k, v2 := range nums2 {
if v1 == v2 {
answer = append(answer, v1) //값이 있으면 추가.
nums2 = removeIndex(nums2, k) //현재 인덱스를 제거
break
}
}
}
return answer
}
func removeIndex(nums1 []int, index int) []int {
return append(nums1[:index], nums1[index+1:]...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment