go 切片数组去重

func RemoveDuplicateElement(stringList []string) []string {
result := make([]string, 0, len(stringList))
temp := map[string]struct{}{}
for _, item := range stringList {
if _, ok := temp[item]; !ok {
temp[item] = struct{}{}
result = append(result, item)
}
}
return result
}
posted @ 2020-12-16 11:46  hubb  阅读(322)  评论(0编辑  收藏  举报