Guest User

Untitled

a guest
Dec 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  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. };
Add Comment
Please, Sign In to add comment