From 69f8dec841865f26245e3191e6191a9b4b4e606a Mon Sep 17 00:00:00 2001 From: Eat-Swap Date: Thu, 23 Jun 2022 00:15:09 +0800 Subject: [PATCH] add: 220622 --- cpp/2206/220622.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 cpp/2206/220622.cpp diff --git a/cpp/2206/220622.cpp b/cpp/2206/220622.cpp new file mode 100644 index 0000000..c6cbc55 --- /dev/null +++ b/cpp/2206/220622.cpp @@ -0,0 +1,16 @@ +#include +#include + +/** + * 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& nums, int k) { + std::nth_element(nums.begin(), nums.begin() + (k - 1), nums.end(), std::greater<>()); + return nums[k - 1]; + } +};