classSolution:deftopKFrequent(self,words: List[str],k:int) -> List[str]: counter =Counter(words) q = [] heapq.heapify(q)for key, value in counter.items(): heapq.heappush(q, (-value, key)) res = heapq.nsmallest(k, q)return [value for key, value in res]