Re: [閒聊] 每日LeetCode已回收

看板Marginalman作者 (是oin的說)時間1年前 (2024/02/16 17:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串685/719 (看更多)
※ 引述 《wu10200512 (廷廷)》 之銘言: :   : 放進vector後sort :   : 跟用priority_queue :   : 誰比較快啊 :   :   : 1481. Least Number of Unique Integers after K Removals :   今天問你刪除k個東西之後 最少能剩下幾種數字 所以就 把數字的種類個數數一數之後 種類就不重要了 從最小的那種開始刪 刪完就完事 ```cpp class Solution { public: int findLeastNumOfUniqueInts(vector<int>& arr, int k) { unordered_map<int,int> paper; for(int u : arr) { auto k = paper.find(u); if(k == paper.end()) { paper.insert({ u , 0 }); k = paper.find(u); } k->second ++; } // for(auto u : paper) // { // printf("%d %d \n", u.first , u.second ); // } // return 0; vector<int> paper2; for(auto u : paper) { paper2.push_back( u.second ); } sort(paper2.begin() , paper2.end() , less() ); int len = paper2.size(); int res = 0; for(int i = 0 ; i < len ; i ++) { if(paper2[i] <= k) { k-= paper2[i]; } else { //printf("%d = %d - %d",res , len , i); res = len - i; break; } } return res; } }; ``` -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.230.129.113 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1708077497.A.BE9.html
文章代碼(AID): #1bpp6vlf (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1bpp6vlf (Marginalman)