Top K Frequent
Given an array nums and a number k, return the k values that appear most often in nums, in any order.
The inputs make the answer unique: no tie decides which values get in.
Constraints
- 1 ≤ length of
nums≤ 100,000 - -10,000 ≤
nums[i]≤ 10,000 - 1 ≤
k≤ the number of different values innums
Example 1
Input
nums = [1,1,1,2,2,3]
k = 2
Output
[1,2]
Why:
1 appears three times and 2 twice; 3 only once.
Example 2
Input
nums = [7]
k = 1
Output
[7]
Why:
The only value.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –