Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 703. Kth Largest Element in a Stream

Posted on 2021-02-11 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class KthLargest {
private:
priority_queue<int, vector<int>, greater<int>> q;
int k;
public:
KthLargest(int k, vector<int>& nums) {
this->k = k;
for (auto& x: nums)
add(x);
}
int add(int val) {
q.push(val);
if (q.size() > k)
q.pop();
return q.top();
}
};
# Heap# Design
LeetCode 76. Minimum Window Substring
LeetCode 119. Pascal's Triangle II
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%