Created
January 13, 2021 06:00
-
-
Save mumunuu/aeba522948071fed5246a2991e24e00e to your computer and use it in GitHub Desktop.
algorithm(leetcode) Intersection of Two Arrays II
This file contains 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 { | |
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