daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     int findKthLargest(vector<int>& nums, int k) {
  4.         auto cmpFunc = [](const int& a, const int& b) { return a > b; };
  5.         priority_queue<int, vector<int>, decltype(cmpFunc)> pQ(cmpFunc);
  6.        
  7.         int ret = nums[0];
  8.         for (const auto& x : nums)
  9.         {
  10.             pQ.push(x);
  11.             if (pQ.size() > k) pQ.pop();
  12.         }
  13.        
  14.         return pQ.top();
  15.     }
  16. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top