Medium
,Array
,Hash Table
,Heap
,Divide and Conquer
,Sorting
Given an integer array nums
and an integer k
, return the k
most frequent elements. You may return the answer in any order.
Example 1:
Example 2:
Constraints:
nums.length
<= 105nums[i]
<= 104k
is in the range [1, the number of unique elements in the array]
.Follow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size.
MarsgoatMay 22, 2023
SheepMay 22, 2023
看了題解發現可以縮
TC:
SC:
Ron ChenMon, May 22, 2023
Yen-Chi ChenMon, May 22, 2023