703. Kth Largest Element in a Stream 發表於 2023-02-13 | 分類於 leetcode problemsolution12345678910111213141516171819class KthLargest {private: priority_queue<int, vector<int>, greater<int>> pq; int size ;public: KthLargest(int k, vector<int>& nums) { size = k; for(int n:nums){ pq.push(n); if(pq.size() > size) pq.pop(); } } int add(int val) { pq.push(val); if(pq.size() > size) pq.pop(); return pq.top(); }}; 實現BST