Advertisement
nikunjsoni

215

May 24th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int findKthLargest(vector<int>& nums, int k) {
  4.         priority_queue<int, vector<int>, greater<int>> heap;
  5.         for(int num:nums){
  6.             heap.push(num);
  7.             if(heap.size() > k)
  8.                 heap.pop();
  9.         }
  10.         return heap.top();
  11.     }
  12. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement