Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int findKthLargest(vector<int>& nums, int k) {
- auto cmpFunc = [](const int& a, const int& b) { return a > b; };
- priority_queue<int, vector<int>, decltype(cmpFunc)> pQ(cmpFunc);
- int ret = nums[0];
- for (const auto& x : nums)
- {
- pQ.push(x);
- if (pQ.size() > k) pQ.pop();
- }
- return pQ.top();
- }
- };
Add Comment
Please, Sign In to add comment