Return the k most frequent values of nums, from the most frequent to the least. If two values have the same frequency, the smaller value comes first. If there are fewer than k different values, return all of them.
Example 1
Input:
top_k_frequent([1, 1, 1, 2, 2, 3], 2)
Output:
[1, 2]
1 appears 3 times, 2 appears 2 times.
Example 2
Input:
top_k_frequent([4, 5, 5, 4], 1)
Output:
[4]
4 and 5 tie, so the smaller value wins.
0 <= len(nums) <= 3 * 10**50 <= k <= 3 * 10**5-10**9 <= nums[i] <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.