【Leetcode_easy】703. Kth Largest Element in a Stream
problem
703. Kth Largest Element in a Stream
题意:
solution1:
priority_queue这个类型没有看明白。。。
class KthLargest {
public:
KthLargest(int k, vector<int>& nums) {
for(int num:nums)
{
q.push(num);
if(q.size()>k) q.pop();
}
K = k;
}
int add(int val) {
q.push(val);
if(q.size()>K) q.pop();
return q.top();
}
private:
priority_queue<int, vector<int>, greater<int>> q;//err...
int K;
};
/**
* Your KthLargest object will be instantiated and called as such:
* KthLargest* obj = new KthLargest(k, nums);
* int param_1 = obj->add(val);
*/
参考
1. Leetcode_easy_703. Kth Largest Element in a Stream;
2. Grandyang;
完
【Leetcode_easy】703. Kth Largest Element in a Stream的更多相关文章
- 【LeetCode】703. Kth Largest Element in a Stream 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 小根堆 日期 题目地址:https://leetco ...
- leetcode 703. Kth Largest Element in a Stream & c++ priority_queue & minHeap/maxHeap
703. Kth Largest Element in a Stream & c++ priority_queue & minHeap/maxHeap 相关链接 leetcode c+ ...
- [LeetCode&Python] Problem 703. Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...
- LeetCode - 703. Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...
- 【LeetCode】215. Kth Largest Element in an Array (2 solutions)
Kth Largest Element in an Array Find the kth largest element in an unsorted array. Note that it is t ...
- 【leetcode】215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- 【LeetCode】215. Kth Largest Element in an Array 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:移除最大值 方法二:排序 方法三:大顶堆 方 ...
- 【easy】215. Kth Largest Element in an Array 第K大的数
class Solution { public: int quicksort(vector<int>& nums, int start, int end, int k){ int ...
- 703. Kth Largest Element in a Stream
题目来源: https://leetcode.com/problems/kth-largest-element-in-a-stream/ 自我感觉难度/真实难度: 题意: 这个题目的意思解读了半天,没 ...
随机推荐
- postgresql学习笔记--基础篇 - copy
1. psql 导入/导出数据 psql支持文件数据导入到数据库,也支持数据库表数据导出到文件中. COPY命令和\copy 命令都支持这两类操作,但两者有如下区别: COPY 命令是SQL命令,\c ...
- 前端实现在线预览pdf、docx、xls、ppt等文件
思路:前台将各种格式的附件上传到服务器----后台通过方法将这些格式的文件转化成图片,前台通过放映ppt的方式将其展示在页面上. 关键点:reveal.js 参考文章:https://www.awes ...
- SVN工作区同步
单击“团队同步”菜单项或“团队同步”视角的“团队”工具栏上的“同步”按钮后,“同步视图”中将显示SVN工作区同步.它提供了从远程检查本地副本的更改类型的概率. 这是“同步视图”中的 “SVN工作空间同 ...
- [Sdoi2013] [bzoj 3198] spring (hash+容斥原理)
题目描述 给出nnn个666维坐标,求有多少对点对满足恰好mmm个位置相等 1<=n<=1051<=n<=10^51<=n<=105 0<=k<=60& ...
- sqlserver内存、会话、连接查询
1.连接查询 select * from sysprocesses where dbid in (select dbid from sysdatabases where name='dbname') ...
- 学到了林海峰,武沛齐讲的Day17-5 内置函数
zip print(list(zip(('a','n','c','d'),(1,2,3)))) =====[('a', 1), ('n', 2), ('c', 3)] 一一对应====元组变列表 ...
- elasticsearch 集群管理(集群规划、集群搭建、集群管理)
一.集群规划 搭建一个集群我们需要考虑如下几个问题: 1. 我们需要多大规模的集群? 2. 集群中的节点角色如何分配? 3. 如何避免脑裂问题? 4. 索引应该设置多少个分片? 5. 分片应该设置几个 ...
- 072_查看所有虚拟机磁盘使用量以及 CPU 使用量信息
#!/bin/bashvirt-df #虚拟机磁盘使用量read -n1 "按任意键继续" keyvirt-top # CPU 使用量
- Bzoj 2301: [HAOI2011]Problem b(莫比乌斯反演+除法分块)
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MB Description 对于给出的n个询问,每次求有多少个数对(x, ...
- Bzoj 3123: [Sdoi2013]森林(主席树+启发式合并)
3123: [Sdoi2013]森林 Time Limit: 20 Sec Memory Limit: 512 MB Description Input 第一行包含一个正整数testcase,表示当前 ...