Search for a command to run...
nums and an integer k, return the k most frequent elements.
nums = [1, 1, 1, 2, 2, 3]
k = 2
[1, 2]
1 appears 3 times, 2 appears 2 times, and 3 appears once.nums.length ≤ 10⁵nums[i] ≤ 10⁴k ≤ number of unique elementsExample 1
[7, 7, 7, 6, 6, 5, 5, 5, 5], 2[5,7]Example 2
[5, 2, 5, 3, 5, 3, 1, 1, 3], 2[5,3][7, 7, 7, 6, 6, 5, 5, 5, 5], 2
[5,7]