LeetCode - Number of Recent Calls
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的更多相关文章
- 【Leetcode_easy】933. Number of Recent Calls
problem 933. Number of Recent Calls 参考 1. Leetcode_easy_933. Number of Recent Calls; 完
- [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 ...
- 【LeetCode】933. Number of Recent Calls 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 队列 相似题目 参考资料 日期 题目地址: ...
- 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 ...
- C#LeetCode刷题之#933-最近的请求次数(Number of Recent Calls)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4134 访问. 写一个 RecentCounter 类来计算最近的 ...
- LeetCode.933-最近通话次数(Number of Recent Calls)
这是悦乐书的第357次更新,第384篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第219题(顺位题号是933).写一个类RecentCounter来计算最近的请求. 它 ...
- [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 ...
- 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 ...
- LeetCode——Number Complement
LeetCode--Number Complement Question Given a positive integer, output its complement number. The com ...
随机推荐
- 改变Cube的Shader下的Alpha值,实现Cube若隐若现的效果。
private float rotaSpeed = 5f; private float timer = 1; private bool flag = true; private float delay ...
- TOleControl(WebBrowser1).Visible := False 这样就可以隐藏浏览器控件
TOleControl(WebBrowser1).Visible := False 这样就可以隐藏浏览器控件了. ------------------------------------------- ...
- 最完整的mac安装caffe
Dependencies : [TIP : Though the official documentation suggests installing Anaconda, it would be be ...
- 【转载】ZooKeeper学习第二期--ZooKeeper安装配置
原文地址(https://www.cnblogs.com/sunddenly/p/4018459.html) 一.Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及 ...
- cv::ACCESS_MASK指定不明确的错误
今天想实现在opencv下使用模拟按键,结果出现cv::ACCESS_MASK指定不明确的错误,查找得到如下原因: 在winnt.h里面有一个cv的命名空间,同样定义了一个ACCESS_MASK,跟o ...
- 4.2 C++虚成员函数
参考:http://www.weixueyuan.net/view/6371.html 总结: virtual关键字仅用于函数声明,如果函数是在类外定义,则不需要再加上virtual关键字了. 在C+ ...
- Linux如何从零开始搭建nfs服务器(centOS6)
Server端 1.打印系统版本 cat /etc/redhat-release uname -r uname -m 2.检查是否安装NFS服务 rpm -aq nfs-utils rpcbind L ...
- SQL-40 表中新增一列
题目描述 存在actor表,包含如下列信息:CREATE TABLE IF NOT EXISTS actor (actor_id smallint(5) NOT NULL PRIMARY KEY,fi ...
- LeetCode 151 翻转字符串里的单词
题目: 给定一个字符串,逐个翻转字符串中的每个单词. 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 ...
- centos7 rocketmq 4.2.0
参考: http://rocketmq.apache.org/docs/quick-start/ 1.环境64bit OS, Linux/Unix/Mac is recommended;64bit J ...