from collections import Counter
class Solution:
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
counts = Counter(nums)
k_frequent = counts.most_common(k)
return [x[0] for x in k_frequent]
No comments:
Post a Comment