class KthLargest {
public:
KthLargest(int k, vector<int>& nums) {
}
int add(int val) {
}
};
/**
* Your KthLargest object will be instantiated and called as such:
* KthLargest* obj = new KthLargest(k, nums);
* int param_1 = obj->add(val);
*/
class KthLargest:
def __init__(self, k: int, nums: List[int]):
self.HEAP = []
self.size = k
for num in nums:
self._push(num)
def _push(self, num):
if len(self.HEAP) < self.size:
heapq.heappush(self.HEAP, num)
else:
if self.HEAP[0] < num:
heapq.heappop(self.HEAP)
heapq.heappush(self.HEAP, num)
def add(self, val: int) -> int:
self._push(val)
return self.HEAP[0]
# Your KthLargest object will be instantiated and called as such:
# obj = KthLargest(k, nums)
# param_1 = obj.add(val)