from typing import List
import heapq
classSolution:deftopKFrequent(self, words: List[str], k:int)-> List[str]:
dic ={}for n in words:
dic[n]= dic.setdefault(n,0)+1
heap =[]for key, value in dic.items():
heapq.heappush(heap,(-value, key))
res =[]for _ inrange(k):
res.append(heapq.heappop(heap)[1])return res