diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/kth_largest_element_stream.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/kth_largest_element_stream.cpp')
-rw-r--r-- | other/kth_largest_element_stream.cpp | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/other/kth_largest_element_stream.cpp b/other/kth_largest_element_stream.cpp deleted file mode 100644 index 3ef8b3c..0000000 --- a/other/kth_largest_element_stream.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// 703. Kth Largest Element in a Stream -#include "leetcode.h" - -/* - * design a class to find the k'th largest element in a stream. note that it is - * the k'th largest element in the sorted order, not the k'th distinct element. - * implement 'KthLargest' class: - * - KthLargest(int k, int[] nums) initialises the objct with the integer 'k' - * and the stream of integers 'nums' int add(int val) appends the integer 'val' - * to the stream and returns the element representing the k'th largest stream - * element - */ - -class KthLargest { - priority_queue<int, vector<int>, greater<int>> pq; - int size; - -public: - KthLargest(int k, vector<int> &nums) { - size = k; - for (int i = 0; i < nums.size(); i++) { - pq.push(nums[i]); - if (pq.size() > k) - pq.pop(); - } - } - int add(int val) { - pq.push(val); - if (pq.size() > size) - pq.pop(); - return pq.top(); - } -}; - -int main() { - vector<int> nums = {4, 5, 8, 2}; - KthLargest *obj = new KthLargest(3, nums); - printf("%d\n", obj->add(3)); // expect: 4 - printf("%d\n", obj->add(5)); // expect: 5 - printf("%d\n", obj->add(10)); // expect: 5 - printf("%d\n", obj->add(9)); // expect: 8 - printf("%d\n", obj->add(4)); // expect: 8 -} |