kth-largest-element-in-an-array
1.0.0
Kth Largest Element in an Array
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1
#include <bits/stdc++.h>
2
3
using namespace
std;
4
5
class
Solution
6
{
7
public
:
8
int
findKthLargest
(vector<int>& nums,
int
k)
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
}
20
};
21
22
int
main
()
23
{
24
25
return
0;
26
}
Solution
Definition
main.cpp:6
Solution::findKthLargest
int findKthLargest(vector< int > &nums, int k)
Definition
main.cpp:8
main
int main()
Definition
main.cpp:22
main.cpp
Generated by
1.9.8