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. javascript es6系列教程 - 不定参数与展开运算符(...)

    三个点(...)在es6中,有两个含义: 用在形参中, 表示传递给他的参数集合, 类似于arguments, 叫不定参数. 语法格式:  在形参面前加三个点( ... ) 用在数组前面,可以把数组的值 ...

  2. C数据结构 : 线性表 与 链表

    一.线性表 一般表现为数组,使用一组地址连续的存储单元依次存储数据元素,如图: 它具有如下特点: 长度固定,必须在分配内存之前确定数组的长度. 存储空间连续,即允许元素的随机访问. 存储密度大,内存中 ...

  3. css动画库

    转载自:http://www.cnblogs.com/starof/p/4968769.html 本文作者starof,因知识本身在变化,作者也在不断学习成长,文章内容也不定时更新,为避免误导读者,方 ...

  4. DevExpress v18.1新版亮点——Analytics Dashboard篇(二)

    用户界面套包DevExpress v18.1日前正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress Analytics Dashboard v18.1 的新功能,快 ...

  5. AbstractBootstrap.bind()

    ------------------headContext也就是pipeline最开头的那个handlercontext中的bind方法@Override public void bind( Chan ...

  6. 关于对Access数据库的学习报告

    学习Access数据库的报告 一.前言 一开始我对access一窍不通,甚至不知道它是干什么的,后来经过网上资料的查阅对它略有了解.microsoft office access是由微软发布的关联式数 ...

  7. Alpha冲刺1

    前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/9948330.html 作业博客:https://edu.cnblogs.com/campus/ ...

  8. linux系统中对SSD硬盘优化的方法

    在测试虚拟机往分布式存储中写数据的最大性能时,做的一些系统修改 1.ext4文件系统在SSD硬盘是最快的 2.查看当前系统支持的IO调度算法 dmesg | grep -i scheduler 3.查 ...

  9. linux 部署之路 修行不够全靠悟

    考虑到很多孩子不会Linux或Mysql,所以我这里提示一下, 这篇教程里 "有多行代码" 的是给你展示结果的,不用你敲 只有一行的才是要你自己敲进去的.   1.首先更新一下仓库 ...

  10. IE9中input事件与异步事件连用会发生跨域问题

    IE版本中IE8以及IE9以上版本不会存在这个问题唯独IE9 发生跨域问题代码 $("#stock_code").bind("input",function(e ...