[leetcode]Heap-347. Top K Frequent Elements
阿新 • • 發佈:2018-01-13
col () heap air algorithm note -- make nts
Given a non-empty array of integers, return the k most frequent elements.
For example,
Given [1,1,1,2,2,3]
and k = 2, return [1,2]
.
Note:
-
class Solution { public: vector<int> topKFrequent(vector<int>& nums, int k) { unordered_map<int,int> mp; for(auto &i : nums) mp[i]
- Your algorithm‘s time complexity must be better than O(n log n), where n is the array‘s size.
[leetcode]Heap-347. Top K Frequent Elements