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 @ 2021-02-02 13:09  salami_china  阅读(220)  评论(0编辑  收藏  举报