Skip to content

Commit 9c2a25c

Browse files
authored
Create Solution2.cpp
1 parent e4acc50 commit 9c2a25c

File tree

1 file changed

+13
-0
lines changed
  • solution/0200-0299/0215.Kth Largest Element in an Array

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int findKthLargest(vector<int>& nums, int k) {
4+
priority_queue<int, vector<int>, greater<int>> minQ;
5+
for (int x : nums) {
6+
minQ.push(x);
7+
if (minQ.size() > k) {
8+
minQ.pop();
9+
}
10+
}
11+
return minQ.top();
12+
}
13+
};

0 commit comments

Comments
 (0)