当前位置:网站首页>LeetCode - 362 敲击计数器(设计)
LeetCode - 362 敲击计数器(设计)
2022-07-25 15:32:00 【三岁就很萌@D】


双端队列

class HitCounter {
private Deque<Integer> deque;
public HitCounter() {
deque = new LinkedList<>();
}
public void hit(int timestamp) {
deque.offerLast(timestamp);
}
public int getHits(int timestamp) {
while(deque.size()!= 0 && timestamp >= (deque.peekFirst() + 300))
deque.pollFirst();
return deque.size();
}
}
/** * Your HitCounter object will be instantiated and called as such: * HitCounter obj = new HitCounter(); * obj.hit(timestamp); * int param_2 = obj.getHits(timestamp); */
边栏推荐
- 2021 Shanghai sai-d-cartland number variant, DP
- 2019 Shaanxi Provincial race K-variant Dijstra
- 2016 CCPC network trial c-change root DP good question
- <栈模拟递归>
- Pytorch学习笔记--常用函数总结2
- 使用cpolar建立一个商业网站(如何购买域名)
- Cf888g clever dictionary tree + violent divide and conquer (XOR minimum spanning tree)
- matlab 优化工具 manopt 安装
- IOS interview questions
- mouseover和mouseenter的区别
猜你喜欢

你准备好脱离“内卷化怪圈”了吗?

window系统黑窗口redis报错20Creating Server TCP listening socket *:6379: listen: Unknown error19-07-28

Node learning

Distributed principle - what is a distributed system

ML - 语音 - 深度神经网络模型

Idea - click the file code to automatically synchronize with the directory

Get the ask code corresponding to the key pressed by the keyboard

Phased summary of the research and development of the "library management system -" borrowing and returning "module

MySQL—用户和权限管控

带你创建你的第一个C#程序(建议收藏)
随机推荐
C#精挑整理知识要点11 委托和事件(建议收藏)
<栈模拟递归>
CF365-E - Mishka and Divisors,数论+dp
The development summary of the function of fast playback of audio and video in any format on the web page.
How to solve the login problem after the 30 day experience period of visual stuido2019
ML - 自然语言处理 - 自然语言处理简介
Pytorch学习笔记--常用函数总结3
数据系统分区设计 - 请求路由
Word 样式模板复制到另一文档
No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac
Are you ready to break away from the "involution circle"?
GAMES101复习:变换
Pytorch学习笔记--常用函数总结2
Cf566a greed + dictionary tree
2019浙江省赛C-错排问题,贪心
如何解决跨域问题
< stack simulation recursion >
Distributed principle - what is a distributed system
获取键盘按下的键位对应ask码
P4552 differential