Skip to content

Instantly share code, notes, and snippets.

@shootacean
Created February 16, 2019 14:08
Show Gist options
  • Save shootacean/5c8351626a7c61297535cc0edaa2ae6a to your computer and use it in GitHub Desktop.
Save shootacean/5c8351626a7c61297535cc0edaa2ae6a to your computer and use it in GitHub Desktop.
// 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