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. 关于LinkedList for OpenJDK

    概述      LinkedList采用底层采用双向链表结构,与ArrayList的数组结构不一样.LinkedList因数据结构不一样,不需要申请连续内存,可以利用碎片内存.元素保存数据内容外还需要 ...

  2. .NET Core初览

    .NET Core 初览的应用场景为游戏服务器开发.所以测试在侧重点上更强于IO和密集型计算 网络IO: NetCore:60%CPU QPS 56W C++:31%CPU QPS 58W C++:6 ...

  3. Substring Anagrams

    Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Strings ...

  4. 003_Python3 基本数据类型

    1.Python 中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建. 在 Python 中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存 ...

  5. 2019-2020 ICPC, Asia Jakarta Regional Contest

    目录 Contest Info Solutions A. Copying Homework C. Even Path E. Songwriter G. Performance Review H. Tw ...

  6. Cogs 750. 栅格网络(对偶图)

    栅格网络流 ★★☆ 输入文件:flowa.in 输出文件:flowa.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] Bob 觉得一般图的最大流问题太难了,他不知道如何解决, ...

  7. 同一个类里@Cacheable缓存不起作用

    问题原因: 注解@Cacheable是使用AOP代理实现的 ,通过创建内部类来代理缓存方法,类内部的方法调用类内部的缓存方法不会走代理,所以就不能正常创建缓存,所以每次都需要去调用数据库. 解决方法: ...

  8. OpenFOAM动网格技术介绍【转载】

    转载自:http://blog.sina.com.cn/s/blog_e256415d0101nfhp.html Chalmers大学的Andreu Oliver González对OpenFOAM中 ...

  9. 面试题小议---BY gremount

    Problem 1:  两个烧杯,一个放糖一个放盐,用勺子舀一勺糖到盐,搅拌均匀,然后舀一勺混合物会放糖的烧杯,问你两个烧杯哪个杂质多? 提示:相同.(1)可以用一个特殊数据计算一下,可以得到两个烧杯 ...

  10. Alpha项目冲刺! Day2-产出

    各个成员今日完成的任务 林恩:任务分工,博客撰写,设计设置等模块 杨长元:学习安卓本地数据库建立 李震:如何写登录界面登录页面,如何下载模板 胡彤:连接服务端 寇永明:提供页面 王浩:提供页面 李杰: ...