Priority Queue


  • 1
    U
    class Solution {
    public:
        int findKthLargest(vector<int>& nums, int k) {
                   
        std::priority_queue< int, std::vector<int> > p;
    
        for (auto num: nums)
            p.emplace(num);
    
        auto count = 0;
        while (count < k-1)
        {
            std::cout << p.top() << "\t";
            p.pop();
            count ++;
        }
    
        return p.top();
            
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.