当前位置:网站首页>[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);
*/
边栏推荐
- 个人博客搭建与美化
- About vctk datasets
- 图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
- About the general input operation mode of unity
- 基础知识之二——STA相关的基本定义
- 微生物健康,食品微生物检测为什么很重要
- "Open math input panel" in MathType editing in win11 is gray and cannot be edited
- Impact relay zc-23/dc220v
- Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.
- JS to convert numbers into Chinese characters for output
猜你喜欢
Zero of DC learning notes -- overview and basic process introduction
微研所,微生物检验中常用的生化反应
Complete software development process
编译安装oh-my-zsh
Kongyiji's first question: how much do you know about service communication?
【Qt5-基础篇】随机数显示屏展示
uniapp官方组件点击item无效,解决方案
图的连通性基础
3dsmax插件开发遍历节点对象和Object获取及INode变换矩阵说明
Impact relay zc-23/dc220v
随机推荐
Dls-20 double position relay 220VDC
DC學習筆記正式篇之零——綜述與基本流程介紹
Service grid ASM year end summary: how do end users use the service grid?
Unknown database连接数据库错误
Pre training / transfer learning of models
Service grid ASM year end summary: how do end users use the service grid?
为什么要搭建个人博客
Using recyclerreview to show banner is very simple
元宇宙为 VR/AR 带来的新机会
Analyzing the wisdom principle in maker education practice
小程序自定义宫格
visual studio 2019 下载
二季度最后一天
User defined annotation implementation verification
JS to convert numbers into Chinese characters for output
dc_labs--lab1的学习与总结
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"?
45岁程序员告诉你:程序员为什么要跳槽,太真实...
用recyclerReview展示Banner,很简单
1175. Prime Arrangements