Skip to content

Latest commit

 

History

History
17 lines (16 loc) · 344 Bytes

kth-largest-element-in-array.md

File metadata and controls

17 lines (16 loc) · 344 Bytes

Kth Largest Element in Array

class Solution {
public:
    int findKthLargest(vector<int>& nums, int k) {
        priority_queue<int, vector<int>, greater<>> pq;
        for(auto N : nums) {
            pq.push(N);
            if(pq.size() > k) {
                pq.pop();
            }
        }
        return pq.top();
    }
};