leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0215.cpp (281B)


      1 class Solution {
      2   public:
      3     int findKthLargest(vector<int> &nums, int k) {
      4         priority_queue<int, vector<int>, greater<int>> pq;
      5 
      6         for (int num : nums) {
      7             pq.push(num);
      8             if (pq.size() > k) pq.pop();
      9         }
     10 
     11         return pq.top();
     12     }
     13 };