6 lines in C++ used STL Heap


  • 0
    W
    int findKthLargest(vector<int>& nums, int k) {
            make_heap(nums.begin(),nums.end());
            for(int i=0;i<k-1;i++) {
                pop_heap(nums.begin(),nums.end());
                nums.pop_back();
            }
            return nums.front();
    }

Log in to reply
 

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