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的更多相关文章

  1. 【LeetCode】703. Kth Largest Element in a Stream 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 小根堆 日期 题目地址:https://leetco ...

  2. 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+ ...

  3. [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 ...

  4. 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 ...

  5. 【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 ...

  6. 【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 ...

  7. 【LeetCode】215. Kth Largest Element in an Array 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:移除最大值 方法二:排序 方法三:大顶堆 方 ...

  8. 【easy】215. Kth Largest Element in an Array 第K大的数

    class Solution { public: int quicksort(vector<int>& nums, int start, int end, int k){ int ...

  9. 703. Kth Largest Element in a Stream

    题目来源: https://leetcode.com/problems/kth-largest-element-in-a-stream/ 自我感觉难度/真实难度: 题意: 这个题目的意思解读了半天,没 ...

随机推荐

  1. Vue中使用markdown

    markdown 是什么?? 1) 使用marked解析markdown文字 这个就只是解析markdown文字,并不能编辑,倒是可以从数据库中读取markdown文字进行解析,另外代码高亮还要另外解 ...

  2. Linux监控系统概览

    自从Linux系统诞生之始,监控系统就随之出现. 当然说到监控系统,我们就必须聊到SNMP协议,SNMP分为管理端(NMP)和被管理端. 管理端周期性的到被监控端采集数据,被监控端还需要有权限收集数据 ...

  3. JavaScript是如何工作的02:深入V8引擎&编写优化代码的5个技巧

    概述 JavaScript引擎是执行 JavaScript 代码的程序或解释器.JavaScript引擎可以实现为标准解释器,或者以某种形式将JavaScript编译为字节码的即时编译器. 以为实现J ...

  4. linux系列(十九):firewall-cmd命令

    1.命令格式 firewall-cmd [选项] [参数] 2.命令功能: 简单来说是一个防火墙管理工具. 3.简单使用: systemctl start firewalld # 启动, system ...

  5. 使用Ajax和一般处理程序实现文件上传与下载

    1.使用HTML的input标签 <input type="file" multiple="multiple" id="file_load&qu ...

  6. Ubuntu上配置vtk开发环境——基于visual studio code 与 gcc

    环境说明 vtk版本7.1.1 visual studio 1.16.1 Ubuntu 16.04 + 自带的gcc 编译过程与windows下类似还好,运行自己的代码开始面对cmake与make的各 ...

  7. codeforces164A

    Variable, or There and Back Again CodeForces - 164A Life is not easy for the perfectly common variab ...

  8. MyBatis中in 的使用方法

    在MyBatis中使用in关键字参数为集合时,需要使用到foreach标签. 下面详细介绍以下foreach标签的几个参数 foreach属性.png 实例: <select id=" ...

  9. OpenFOAM中的热传导?【翻译】

    翻译自:CFD-online 帖子地址:http://www.cfd-online.com/Forums/openfoam/70758-conductive-heat-transfer-openfoa ...

  10. android通用的UUID唯一标示符

    http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id 版权声明:本文为博主原创文章,未经博主允许 ...