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. 哇!吐槽!oh shit

    一个jsp写了5000行,我尼玛醉了,看晕了-2017年10月12日10:19:40

  2. LightOJ - 1214-Large Division(数学,同余)

    链接: https://vjudge.net/problem/LightOJ-1214 题意: Given two integers, a and b, you should check whethe ...

  3. Python-sokect 示例

    server: #coding=utf-8 import socket _sokect =socket.socket() #创建sokect _host =socket.gethostname() # ...

  4. 005_Python3 运算符

    什么是运算符? 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中,4 和 5 被称为操作数,"+" 称为运算符. Python语言支持以下类型的运算 ...

  5. java大文件上传解决方案

    最近遇见一个需要上传百兆大文件的需求,调研了七牛和腾讯云的切片分段上传功能,因此在此整理前端大文件上传相关功能的实现. 在某些业务中,大文件上传是一个比较重要的交互场景,如上传入库比较大的Excel表 ...

  6. splay树 1285 宠物收养所

    #include<cstdio> #include<iostream> using namespace std; int shu[80004][2],n,size,root,k ...

  7. 小程序demo项目实践

    今天开始做一个简单的小程序,做的过程中势必会有一些知识经验需要记录 项目初始化 首先创建好一个小程序项目,在app.wxss里面将自带的css样式统统去除,加上自己写的初始化样式 小程序目前不支持*号 ...

  8. c++ ros 计算两点距离

    #include <iostream> /* puts, printf */ #include <time.h> /* time_t, struct tm, time, loc ...

  9. 使用Spring Ehcache二级缓存优化查询性能

    最近在对系统进行优化的时候,发现有些查询查询效率比较慢,耗时比较长, 通过压测发现,主要耗费的性能 消耗在 查询数据库,查询redis 数据库:连接池有限,且单个查询不能消耗大量的连接池,占用大量IO ...

  10. shell wait 和sleep 对比

    wait 在 shell 中使用 wait 是在等待上一批或上一个脚本执行完(即上一个的进程终止),再执行wait之后的命令. sleep sleep 1 睡眠1秒 sleep 1s 睡眠1秒 sle ...