123456789101112131415 |
- package dto
- func UniqueSlice(slice []string) []string {
- seen := make(map[string]struct{}) // 使用空结构体节省内存
- result := []string{}
- for _, value := range slice {
- if _, ok := seen[value]; !ok {
- seen[value] = struct{}{}
- result = append(result, value)
- }
- }
- return result
- }
|