推 PyTorch: 大師 02/16 10:46
放進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;
}
};
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.25.40.62 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1708051092.A.71E.html