kth-largest-element-in-an-array 1.0.0
Kth Largest Element in an Array
Loading...
Searching...
No Matches
Solution Class Reference

Public Member Functions

int findKthLargest (vector< int > &nums, int k)
 

Detailed Description

Definition at line 5 of file main.cpp.

Member Function Documentation

◆ findKthLargest()

int Solution::findKthLargest ( vector< int > &  nums,
int  k 
)
inline

Definition at line 8 of file main.cpp.

9 {
10 priority_queue<int> max_heap(nums.begin(), nums.end());
11 int kth = max_heap.top();
12 max_heap.pop();
13 for (int i = 1; i < k; ++i)
14 {
15 kth = max_heap.top();
16 max_heap.pop();
17 }
18 return kth;
19 }

The documentation for this class was generated from the following file: