Skip to content

Commit adb183e

Browse files
committed
Time: 145 ms (35.24%), Space: 47.2 MB (60.53%) - LeetHub
1 parent 7f649fe commit adb183e

File tree

1 file changed

+14
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)