广告平台(站长下代理使用)
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

38 řádky
768 B

  1. package utils
  2. func RemoveDuplicateString(elms []string) []string {
  3. res := make([]string, 0, len(elms))
  4. temp := map[string]struct{}{}
  5. for _, item := range elms {
  6. if _, ok := temp[item]; !ok {
  7. temp[item] = struct{}{}
  8. res = append(res, item)
  9. }
  10. }
  11. return res
  12. }
  13. func RemoveDuplicateInt(elms []int) []int {
  14. res := make([]int, 0, len(elms))
  15. temp := map[int]struct{}{}
  16. for _, item := range elms {
  17. if _, ok := temp[item]; !ok {
  18. temp[item] = struct{}{}
  19. res = append(res, item)
  20. }
  21. }
  22. return res
  23. }
  24. func RemoveDuplicateInt64(elms []int64) []int64 {
  25. res := make([]int64, 0, len(elms))
  26. temp := map[int64]struct{}{}
  27. for _, item := range elms {
  28. if _, ok := temp[item]; !ok {
  29. temp[item] = struct{}{}
  30. res = append(res, item)
  31. }
  32. }
  33. return res
  34. }