commit 110291debf45769a678f8d97592b0ea0ce1f7264
parent 257b78260e9fdf450bb2f02d82353a36961d6778
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 23 Feb 2023 11:14:46 +0100
Data Structure II: Day 20
Diffstat:
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/Problems/0215.cpp b/Problems/0215.cpp
@@ -0,0 +1,13 @@
+class Solution {
+public:
+ int findKthLargest(vector<int> &nums, int k) {
+ priority_queue<int, vector<int>, greater<int>> pq;
+
+ for (int num : nums) {
+ pq.push(num);
+ if (pq.size() > k) pq.pop();
+ }
+
+ return pq.top();
+ }
+};
diff --git a/README.md b/README.md
@@ -164,6 +164,7 @@ for solving problems.
| 0209 | Medium | [Minimum Size Subarray Sum](Problems/0209.cpp) |
| 0210 | Medium | [Course Schedule II](Problems/0210.cpp) |
| 0213 | Medium | [House Robber II](Problems/0213.cpp) |
+| 0215 | Medium | [Kth Largest Element in an Array](Problems/0215.cpp) |
| 0217 | Easy | [Contains Duplicate](Problems/0217.cpp) |
| 0221 | Medium | [Maximal Square](Problems/0221.cpp) |
| 0222 | Medium | [Count Complete Tree Nodes](Problems/0222.cpp) |