O(n) two liner C++


  • 0
    M

    Yep, there's a C++ function for this.

    class Solution {
    public:
        int findKthLargest(vector<int>& nums, int k) {
            std::nth_element(nums.begin(),nums.begin()+nums.size()-k,nums.end());
            return *(nums.begin()+nums.size()-k);
        }
    };
    

Log in to reply
 

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