[leetcode_215] Kth Largest Element in an Array

Finding the k-th largest number. I took a shortcut and just used a direct sort. The proper approach should be simulating quickselect.

1
2
3
4
5
6
7
class Solution {
public:
    int findKthLargest(vector<int>& nums, int k) {
        sort(nums.begin(), nums.end(), greater<int>());
        return nums[k - 1];
    }
};