add: 220622

This commit is contained in:
Eat-Swap 2022-06-23 00:15:09 +08:00
parent c2edc81e2b
commit 69f8dec841
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
1 changed files with 16 additions and 0 deletions

16
cpp/2206/220622.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <vector>
#include <algorithm>
/**
* 215. Kth Largest Element in an Array
* Given an integer array nums and an integer k, return the kth largest element in the array.
* Note that it is the kth largest element in the sorted order, not the kth distinct element.
*/
class Solution {
public:
int findKthLargest(std::vector<int>& nums, int k) {
std::nth_element(nums.begin(), nums.begin() + (k - 1), nums.end(), std::greater<>());
return nums[k - 1];
}
};