Re: [閒聊] 每日leetcode

看板Marginalman作者 (通通打死)時間1年前 (2024/08/12 23:57), 1年前編輯推噓1(102)
留言3則, 3人參與, 1年前最新討論串701/1554 (看更多)
忘記C++的pq是max_heap了 花了我一點時間debug 一二三四五 == class KthLargest { public: int k; priority_queue<int, vector<int>, greater<int>> pq; KthLargest(int k, vector<int>& nums) { this->k = k; for(auto num : nums) { this->pq.push(num); while (this->pq.size() > k) { this->pq.pop(); } } } int add(int val) { this->pq.push(val); while (this->pq.size() > this->k) { this->pq.pop(); } return this->pq.top(); } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1723478224.A.C4C.html ※ 編輯: DJYOMIYAHINA (125.229.37.69 臺灣), 08/12/2024 23:57:23

08/12 23:57, 1年前 , 1F
大師
08/12 23:57, 1F

08/13 00:25, 1年前 , 2F
大師
08/13 00:25, 2F

08/13 15:25, 1年前 , 3F
大師
08/13 15:25, 3F
文章代碼(AID): #1ckZ3GnC (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ckZ3GnC (Marginalman)