← 返回 microsoft 的题目列表Top K Frequent Elements
类型:online_judge
microsoft
Given a non-empty integer array, return the top k frequent elements.
Example 1:
Input: nums = [1,1,1,2,2,3], k = 2
Output: [1, 2]
Constraints:
You may assume k is always valid, and 1 ≤ k ≤ number of unique elements in the array.
Your algorithm's time complexity must be better than O(nlogn), where n is the size of the array.
Example
Input
nums = [1,1,1,2,2,3], k = 2