Re: [閒聊] 每日LeetCode

作者: wu10200512 (廷廷)   2024-02-16 10:38:10
放進vector後sort
跟用priority_queue
誰比較快啊
1481. Least Number of Unique Integers after K Removals
class Solution {
public:
int findLeastNumOfUniqueInts(vector<int>& arr, int k) {
unordered_map<int, int> mp;
for(const int& n:arr){
mp[n]++;
}
priority_queue<int, vector<int>, greater<int>> pq;
for(const auto& n:mp){
pq.push(n.second);
}
while(k>0){
k-=pq.top();
pq.pop();
}
if(k==0) return pq.size();
return pq.size()+1;
}
};
作者: PyTorch (屁眼火炬)   2024-02-16 10:46:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com