当前位置:网站首页>【队列】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);
*/
边栏推荐
猜你喜欢
Service grid ASM year end summary: how do end users use the service grid?
K210工地安全帽
[network packet loss and network delay? This artifact can help you deal with everything!]
DC学习笔记正式篇之零——综述与基本流程介绍
Introduction and principle analysis of cluster and LVS
Win11安装redis 数据库以及redis desktop manager的下载
DLS-42/6-4 DC110V双位置继电器
Double position relay dls-5/2 dc220v
Locking relay ydb-100, 100V
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"?
随机推荐
JS方法大全的一个小文档
visual studio 2019 快捷键备忘
DLS-42/6-4 DC110V双位置继电器
技术人进阶画业务大图,手把手教学来了
js中把数字转换成汉字输出
StrictMode卡顿与泄漏检测-StrictMode原理(2)
TCP三次握手为什么不是两次或四次
基础知识之一——STA基础概述
System.CommandLine版CSRebot
C语言一点点(未来可会增加)
"Open math input panel" in MathType editing in win11 is gray and cannot be edited
Digital IC design process summary
[LeetCode] 两数之和【1】
Open3D 点云颜色渲染
TypeError: Argument ‘angle‘ can not be treated as a double
Visual studio 2019 shortcut notes
Use of typora
【Qt5-基础篇】随机数显示屏展示
Exploring the road of steam education innovation in the Internet Era
06. on several ways of redis persistence