蛋蛋星球 后台端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
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. }