当前位置:网站首页>[queue] 933 Number of Recent Calls
[queue] 933 Number of Recent Calls
2022-07-01 01:30:00 【Twilight_ years】
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.
The question : request t( Unit is milliseconds), return [t-3000,t] The number of requests for
Design : queue
fifo
Kick out all non conformances when entering
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);
*/边栏推荐
- Digital IC design process summary
- [问题已处理]-nvidia-smi命令获取不到自身容器的GPU进程和外部的GPU进程号
- 微生物健康,食品微生物检测为什么很重要
- Mustache syntax
- 【office办公-pdf篇】pdf合并与拆分让我们摆脱付费软件的功能限制好不好
- Dx-11q signal relay
- Openmv and k210 of the f question of the 2021 video game call the openmv API for line patrol, which is completely open source.
- [learning notes] double + two points
- 【Qt5-基础篇】随机数显示屏展示
- 基础知识之一——STA基础概述
猜你喜欢

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

WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑

Q play soft large toast to bring more comfortable sleep

软件开发完整流程

Interpreting the scientific and technological literacy contained in maker Education

Exploring the road of steam education innovation in the Internet Era

Double position relay dls-5/2 dc220v

未来的 Web3会带来什么?

For the first time in more than 20 years! CVPR best student thesis awarded to Chinese college students!

New opportunities for vr/ar brought by metauniverse
随机推荐
[network packet loss and network delay? This artifact can help you deal with everything!]
Impact relay zc-23/dc220v
About the general input operation mode of unity
未来的 Web3会带来什么?
【模拟】922. Sort Array By Parity II
Zero of DC learning notes -- overview and basic process introduction
Complete software development process
Basic knowledge 3 - standard unit library
sort自定义函数
图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
Two position relay st2-2l/ac220v
图的连通性基础
微生物健康,食品微生物检测为什么很重要
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"?
【多源bfs】934. Shortest Bridge
微生物检测,土壤微生物的作用有哪些?
Inspire students' diversified thinking with steam Education
面对产业互联网的时候,甚至还用消费互联网的方式和方法去落地和实践产业互联网
Open3D 点云颜色渲染
OCR的一些项目