当前位置:网站首页>【队列】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?
- JS to convert numbers into Chinese characters for output
- TypeError: Argument ‘angle‘ can not be treated as a double
- 解析融合学科本质的创客教育路径
- Exploring the road of steam education innovation in the Internet Era
- K210门禁毕设
- [leetcode] climb stairs [70]
- 奇偶链表[链表操作的两种大方向]
- Looksrare team's "cash out" caused disturbance
- 1175. Prime Arrangements
猜你喜欢

Double position relay dls-5/2 dc220v

Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images

K210 site helmet
![[network packet loss and network delay? This artifact can help you deal with everything!]](/img/c4/f733b23327458b9266b9cbcccb6f14.png)
[network packet loss and network delay? This artifact can help you deal with everything!]

解读创客教育所蕴含的科技素养

解决IDEA:Class ‘XXX‘ not found in module ‘XXX‘

Technical personnel advanced to draw a big picture of business, hand-in-hand teaching is coming

DC學習筆記正式篇之零——綜述與基本流程介紹

Kongyiji's first question: how much do you know about service communication?

闭锁继电器YDB-100、100V
随机推荐
Docker 部署 MySQL 8
sort自定义函数
Service grid ASM year end summary: how do end users use the service grid?
做生意更加务实
Exploration and practice of "flow batch integration" in JD
uniapp官方组件点击item无效,解决方案
OCR的一些项目
Installing mongodb database in Windows Environment
pull_ to_ refresh
Parity linked list [two general directions of linked list operation]
[LeetCode] 两数之和【1】
Open3D 点云颜色渲染
双位置继电器DLS-5/2 DC220V
TypeError: Argument ‘angle‘ can not be treated as a double
Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support
孔乙己第一问之服务通信知多少?
TCP三次握手为什么不是两次或四次
ASCII、Unicode、GBK、UTF-8之间的关系
Mustache syntax
[learning notes] double + two points