2 lines C++ solution


  • 2
    K
    class Solution {
    public:
        int findKthLargest(vector<int>& nums, int k) {
            nth_element(nums.begin(),nums.begin()+k-1,nums.end(),greater<int>());
            return nums[k-1];
        }
    };

  • 0
    M

    In C++, this is the way to do it. Thanks!


Log in to reply
 

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