Skip to content

Commit 4884c73

Browse files
[CREATE] [CPP] 215. Kth Largest Element in an Array
1 parent 7062852 commit 4884c73

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public:
3+
int findKthLargest(vector<int>& nums, int k) {
4+
priority_queue<int, vector<int>, greater<int>> pq(nums.begin(), nums.end());
5+
while (pq.size() > k)pq.pop();
6+
return pq.top();
7+
}
8+
};

0 commit comments

Comments
 (0)