当前位置:网站首页>【队列】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);
*/边栏推荐
- uniapp官方组件点击item无效,解决方案
- JS方法大全的一个小文档
- qt5-MVC:数据可视化的层次揭秘
- 分割链表[先取next再斩断链表防止断链]
- Call the classic architecture and build the model based on the classic
- Two position relay st2-2l/ac220v
- 人穷志不短,穷学生也能玩转树莓派
- 5. TPM module initialization
- Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
- DLS-20型双位置继电器 220VDC
猜你喜欢

DLS-42/6-4 DC110V双位置继电器

TCP三次握手为什么不是两次或四次

【qt5-tab标签精讲】Tab标签及内容分层解析

Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support

One of the basics - overview of sta Basics

qt5-MVC:数据可视化的层次揭秘

uniapp官方组件点击item无效,解决方案
![分割链表[先取next再斩断链表防止断链]](/img/eb/708ab20c13df75f4dbd2d6461d3602.png)
分割链表[先取next再斩断链表防止断链]

Use of typora

Orb-slam2 source code learning (II) map initialization
随机推荐
TCP三次握手为什么不是两次或四次
Basic knowledge of software and hardware -- diary (1)
(学习力+思考力) x 行动力,技术人成长的飞轮效应总结
Construction and beautification of personal blog
解析创客教育实践中的智慧原理
Pytorch programming knowledge (2)
Visual studio 2019 Download
闭锁继电器YDB-100、100V
一些本质的区别
06. on several ways of redis persistence
数字IC设计流程总结
mysql数据库基础:流程控制
[LeetCode] 两数之和【1】
探索互联网时代STEAM教育创新之路
Docker deployment MySQL 8
【qt5-tab标签精讲】Tab标签及内容分层解析
分割链表[先取next再斩断链表防止断链]
为什么要搭建个人博客
Looksrare team's "cash out" caused disturbance
【go】go 实现行专列 将集合进行转列