def topKFrequent(nums, k):
dict={}
result=[]
for i in nums:
if i in dict:
dict[i]+=1
else:
dict[i]=1
sortDict=sorted(dict.items(),key=lambda d:d[1],reverse=True)
for x in sortDict[:k]:
result.append(x[0])
return result