123456789101112131415 |
- package silce_utils
- // RemoveDuplicates 去除整数切片中的重复元素
- func RemoveDuplicates(nums []int) []int {
- seen := make(map[int]bool)
- var result []int
- for _, num := range nums {
- if _, ok := seen[num]; !ok {
- seen[num] = true
- result = append(result, num)
- }
- }
- return result
- }
|