Write a class RecentCounter to count recent requests.

It has only one method: ping(int t), where t represents some time in milliseconds.

Return the number of pings that have been made from 3000 milliseconds ago until now.

Any ping with time in [t - 3000, t] will count, including the current ping.

It is guaranteed that every call to ping uses a strictly larger value of t than before.

Example 1:

Input: inputs = ["RecentCounter","ping","ping","ping","ping"], inputs = [[],[1],[100],[3001],[3002]]
Output: [null,1,2,3,3] Note: Each test case will have at most 10000 calls to ping.
Each test case will call ping with strictly increasing values of t.
Each call to ping will have 1 <= t <= 10^9.

用queue

class RecentCounter {
Queue<Integer> q; public RecentCounter() {
q = new LinkedList();
} public int ping(int t) {
q.add(t);
while(q.peek() < t - 3000 ){
q.poll();
}
return q.size();
}
} /**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter obj = new RecentCounter();
* int param_1 = obj.ping(t);
*/

LeetCode - Number of Recent Calls的更多相关文章

  1. 【Leetcode_easy】933. Number of Recent Calls

    problem 933. Number of Recent Calls 参考 1. Leetcode_easy_933. Number of Recent Calls; 完

  2. [LeetCode] 933. Number of Recent Calls 最近的调用次数

    Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t r ...

  3. 【LeetCode】933. Number of Recent Calls 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 队列 相似题目 参考资料 日期 题目地址: ...

  4. 109th LeetCode Weekly Contest Number of Recent Calls

    Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t r ...

  5. C#LeetCode刷题之#933-最近的请求次数(Number of Recent Calls)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4134 访问. 写一个 RecentCounter 类来计算最近的 ...

  6. LeetCode.933-最近通话次数(Number of Recent Calls)

    这是悦乐书的第357次更新,第384篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第219题(顺位题号是933).写一个类RecentCounter来计算最近的请求. 它 ...

  7. [Swift]LeetCode933. 最近的请求次数 | Number of Recent Calls

    Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t r ...

  8. 2016.5.15——leetcode:Number of 1 Bits ,

    leetcode:Number of 1 Bits 代码均测试通过! 1.Number of 1 Bits 本题收获: 1.Hamming weight:即二进制中1的个数 2.n &= (n ...

  9. LeetCode——Number Complement

    LeetCode--Number Complement Question Given a positive integer, output its complement number. The com ...

随机推荐

  1. css3 前端开发

    一.前缀: -moz(例如 -moz-border-radius)用于Firefox -webkit(例如:-webkit-border-radius)用于Safari和Chrome. 二.CSS3圆 ...

  2. LeetCode 回溯法 别人的小结 八皇后 递归

    #include <iostream> #include <algorithm> #include <iterator> #include <vector&g ...

  3. vue-router-8-路由组件传参

    在组件中使用$route会使之与其对应路由形成高度耦合,使用props解耦 const User = { props: ['id'], template: '<div>User{{ id ...

  4. SQL-11 获取所有员工当前的manager,如果当前的manager是自己的话结果不显示

    题目描述 获取所有员工当前的manager,如果当前的manager是自己的话结果不显示,当前表示to_date='9999-01-01'.结果第一列给出当前员工的emp_no,第二列给出其manag ...

  5. Ubuntu16.04 python2.7升级python3.5

    正常情况下,你安装好ubuntu16.04版本之后,系统会自带 python2.7版本,如果需要下载新版本的python3.5,就需要进行更新.下面给出具体教程: 1.首先在ubuntu的终端tern ...

  6. CSS学习笔记-01-2D转换模块

    首先,mark 一下  css3 新增 的 2D 转换之 W3school 的链接: http://www.w3school.com.cn/css3/css3_2dtransform.asp 转换是使 ...

  7. 20165326 java第三周学习笔记

    纸质学习笔记 代码托管

  8. 界面设计-Edit控件的Style设置

    以下文字转贴ChinaCock QQ 223717588群: 1. 首先在Form上放一个TEdit类型控件Edit1,最终的效果如下图: 2.选中控件Edit1,点击鼠标右键,在弹出菜单中选择“Ed ...

  9. 联想 Lenovo PWR-G60 无线掌中宝拆机

    从朋友那里弄了台Lenovo PWR-G60,现在已经停产了,淘宝上某店卖的国产WIFI Pineapple貌似就是拿这个刷的,打算出篇DIY教程 现在人在外地,编程器.热风枪.烙铁工具啥的都没有,更 ...

  10. 【Maven】Project configuration is not up-to-date with pom.xml错误解决方法

    导入一个Maven项目之后发现有一个如下的错误: Project configuration is not up-to-date with pom.xml. Run project configura ...