1234567891011121314151617181920 |
- package slice
- func RemoveRepeatElement[T comparable](elements []T) []T {
- if elements == nil || len(elements) == 0 {
- return elements
- }
- result := make([]T, 0)
- tempMap := make(map[T]interface{})
- for _, element := range elements {
- l := len(tempMap)
- tempMap[element] = nil
- if len(tempMap) != l {
- result = append(result, element)
- }
- }
- return result
- }
|