Just Use nth_element in STL!


  • 0
    K
        int findKthLargest(vector<int>& nums, int k) {
            nth_element(nums.begin(), nums.end()-k, nums.end());
            return *(nums.end()-k);
        }
    

Log in to reply
 

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