当前位置:网站首页>[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);
*/边栏推荐
- Looksrare team's "cash out" caused disturbance
- Analyzing the wisdom principle in maker education practice
- Service grid ASM year end summary: how do end users use the service grid?
- 【队列】933. Number of Recent Calls
- DC学习笔记正式篇之零——综述与基本流程介绍
- JS方法大全的一个小文档
- 6月第4周榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
- Two position relay st2-2l/ac220v
- 孙宇晨接受瑞士媒体Bilan采访:熊市不会持续太久
- gin 配置文件
猜你喜欢

孙宇晨接受瑞士媒体Bilan采访:熊市不会持续太久

数字IC设计流程总结

Principes de formation de la programmation robotique

Docker deployment MySQL 8

Service grid ASM year end summary: how do end users use the service grid?

Install redis database and download redis Desktop Manager in win11

图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途

Introduction and principle analysis of cluster and LVS

【Qt5-基础篇】随机数显示屏展示

Dx-11q signal relay
随机推荐
做生意更加务实
K210 access control complete
TypeError: Argument ‘angle‘ can not be treated as a double
【qt5-tab标签精讲】Tab标签及内容分层解析
DC学习笔记正式篇之零——综述与基本流程介绍
User defined annotation implementation verification
基础知识之一——STA基础概述
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number
生意和投资的思考
visual studio 2019 下载
Call the classic architecture and build the model based on the classic
Introduction and principle analysis of cluster and LVS
二季度最后一天
C语言一点点(未来可会增加)
Docker deployment MySQL 8
Open3d point cloud bounding box
neo4j安装、运行以及项目的构建和功能实现
StrictMode带来的思考-StrictMode原理(5)
Mustache syntax
微研所,微生物检验中常用的生化反应