func topKFrequent(nums []int, k int) []int {
var res []int
counts := make(map[int]int)
for _, n := range nums {
counts[n]++
}
for n := range counts {
res = append(res, n)
}
sort.Slice(res, func(i, j int) bool {
return counts[res[i]] > counts[res[j]]
})
return res[:k]
}