当前位置:网站首页>[queue] 933 Number of Recent Calls
[queue] 933 Number of Recent Calls
2022-07-01 01:30:00 【Twilight_ years】
You have a RecentCounter class which counts the number of recent requests within a certain time frame.
Implement the RecentCounter class:
RecentCounter() Initializes the counter with zero recent requests.
int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t].
It is guaranteed that every call to ping uses a strictly larger value of t than the previous call.
The question : request t( Unit is milliseconds), return [t-3000,t] The number of requests for
Design : queue
fifo
Kick out all non conformances when entering
class RecentCounter {
Queue<Integer>q;
public RecentCounter() {
q=new ArrayDeque<>();
}
public int ping(int t) {
q.add(t);
while(t-q.peek()>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);
*/边栏推荐
- System settings large page
- 使用StrictMode-StrictMode原理(1)
- The liquor and tourism sector recovers, and Yaduo continues to dream of listing. How far is it from "the first share of the new accommodation economy"?
- Basic knowledge 3 - standard unit library
- Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base
- Docker deployment MySQL 8
- Typora的使用
- Draw some interesting figures with flutter's canvas
- StrictMode带来的思考-StrictMode原理(5)
- 45岁程序员告诉你:程序员为什么要跳槽,太真实...
猜你喜欢
随机推荐
Use strictmode strictmode principle (1)
Strictmode analysis registration strictmode principle (4)
Solve idea:class' xxx 'not found in module' xxx‘
MFC TCP通信服务端客户端Demo备忘vs2019
【Qt5-基础篇_1】从0开始,德天老师和你一起学习——窗口简介
Analyze the maker education path integrating the essence of discipline
一些本质的区别
Double position relay dls-5/2 dc220v
About the general input operation mode of unity
Koa koa combine routes sub route management
About vctk datasets
【qt5-tab标签精讲】Tab标签及内容分层解析
Introduction and principle analysis of cluster and LVS
Matlab farthest point sampling (FPS improved version)
C# 自定义并动态切换光标
Open3d point cloud color rendering
[dynamic planning] path dp:931 Minimum Falling Path Sum
JS方法大全的一个小文档
Green, green the reed. dew and frost gleam.
Q play soft large toast to bring more comfortable sleep









![[learning notes] structure](/img/55/9623ba97f57eff71c246684e3a2bba.png)