Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- func Solve(slice []int) []int {
- lastIndex := make(map[int]int)
- for i, key := range slice {
- lastIndex[key] = i
- }
- result := []int{}
- for i := len(slice) - 1; i >= 0; i-- {
- value := slice[i]
- if lastIndex[value] == i {
- result = append([]int{value}, result...)
- }
- }
- return result
- }
- func main() {
- numbers := []int{1, 1, 4, 5, 1, 2, 1}
- fmt.Print(Solve(numbers))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement