当前位置:网站首页>【队列】933. Number of Recent Calls
【队列】933. Number of Recent Calls
2022-07-01 00:41:00 【暮色_年华】
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.
题意:请求t(单位为milliseconds),返回[t-3000,t]的请求个数
设计:队列
先进先出
进的时候把不符合的都踢掉
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);
*/边栏推荐
- 【qt5-tab标签精讲】Tab标签及内容分层解析
- For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!
- 软件开发完整流程
- QT5-布局在创作中的理解应用
- K210 site helmet
- 45岁程序员告诉你:程序员为什么要跳槽,太真实...
- K210门禁毕设
- Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
- Windows环境下安装MongoDB数据库
- Dls-42/6-4 dc110v double position relay
猜你喜欢

45岁程序员告诉你:程序员为什么要跳槽,太真实...

Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base

Typora的使用

Exploring the road of steam education innovation in the Internet Era

基础知识之二——STA相关的基本定义

Install redis database and download redis Desktop Manager in win11

用recyclerReview展示Banner,很简单
![[go] go implements row column conversion of sets](/img/d9/6272e55b2d9c6b6fbdf2537773bb83.png)
[go] go implements row column conversion of sets

Principes de formation de la programmation robotique

【网络丢包,网络延迟?这款神器帮你搞定所有!】
随机推荐
【office办公-pdf篇】pdf合并与拆分让我们摆脱付费软件的功能限制好不好
解读创客教育所蕴含的科技素养
Docker deployment MySQL 8
解析融合学科本质的创客教育路径
Pre training / transfer learning of models
蒹葭苍苍,白露为霜。
【Qt5-基础篇】随机数显示屏展示
45岁程序员告诉你:程序员为什么要跳槽,太真实...
做生意更加务实
About vctk datasets
个人博客搭建与美化
"Open math input panel" in MathType editing in win11 is gray and cannot be edited
User defined annotation implementation verification
[leetcode] climb stairs [70]
ASCII、Unicode、GBK、UTF-8之间的关系
K210 site helmet
[learning notes] structure
Q play soft large toast to bring more comfortable sleep
使用StrictMode-StrictMode原理(1)
WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑