题目
解法1:排序 (NlogN)
class Solution(object):
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
count = collections.Counter(nums)
tmp = list(set(nums))
tmp.sort(key = lambda x:count[x],reverse = True)
ans = []
for i in range(k):
ans.append(tmp[i])
return ans;
解法2:heap (Nlogk)
class Solution(object):
def to