Created
October 15, 2017 06:33
-
-
Save acoshift/15f1c0abff4cff7d092ce7523d68df75 to your computer and use it in GitHub Desktop.
remove duplicate: hash map
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 removeDuplicateMap(arr []int) []int { | |
p := make(map[int]struct{}) | |
for _, v := range arr { | |
p[v] = struct{}{} | |
} | |
r := make([]int, 0, len(p)) | |
for v := range p { | |
r = append(r, v) | |
} | |
return r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment