Created
February 16, 2019 14:08
-
-
Save shootacean/5c8351626a7c61297535cc0edaa2ae6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sliceの重複要素を削除 | |
func slimSlice(slice []int) []int { | |
m := make(map[int]int) | |
slim := make([]int, 0) | |
for _, element := range slice { | |
if _, ok := m[element]; !ok { | |
m[element] = 0 | |
slim = append(slim, element) | |
} | |
} | |
return slim | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment