当前位置:网站首页>【队列】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);
*/边栏推荐
- visual studio 2019 下载
- 用Steam教育启发学生多元化思维
- 生意和投资的思考
- [network packet loss and network delay? This artifact can help you deal with everything!]
- 探索互联网时代STEAM教育创新之路
- 做生意更加务实
- Basic knowledge of software and hardware -- diary (1)
- Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base
- 软硬件基础知识学习--小日记(1)
- [问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号
猜你喜欢

二十多年来第一次!CVPR最佳学生论文授予中国高校学生!

Construction and beautification of personal blog

Green, green the reed. dew and frost gleam.

Exploring the road of steam education innovation in the Internet Era

Pre training / transfer learning of models

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

Call the classic architecture and build the model based on the classic
![Split the linked list [take next first and then cut the linked list to prevent chain breakage]](/img/eb/708ab20c13df75f4dbd2d6461d3602.png)
Split the linked list [take next first and then cut the linked list to prevent chain breakage]

【网络丢包,网络延迟?这款神器帮你搞定所有!】

DX-11Q信号继电器
随机推荐
pytorch编程知识(2)
技术人进阶画业务大图,手把手教学来了
数字IC设计流程总结
Service grid ASM year end summary: how do end users use the service grid?
【网络丢包,网络延迟?这款神器帮你搞定所有!】
[问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号
Installing mongodb database in Windows Environment
Two position relay st2-2l/ac220v
(learning power + thinking power) x action power, summary of flywheel effect on the growth of technicians
3dsmax插件开发遍历节点对象和Object获取及INode变换矩阵说明
User defined annotation implementation verification
DX-11Q信号继电器
(学习力+思考力) x 行动力,技术人成长的飞轮效应总结
MFC TCP通信服务端客户端Demo备忘vs2019
System.CommandLine版CSRebot
Call the classic architecture and build the model based on the classic
【学习笔记】构造
MFC TCP communication server client demo notes vs2019
Inspire students' diversified thinking with steam Education
[LeetCode] 两数之和【1】