当前位置:网站首页>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); */
边栏推荐
- Seata中jdbc下只有一个lib嘛?
- JVM parameter configuration details
- 我想问下变量配置功能是只能在SQL模式下使用吗
- Box avoiding mouse
- wait()和sleep()的区别理解
- In depth: micro and macro tasks
- User defined annotation verification API parameter phone number
- ML - 自然语言处理 - 关键技术
- Find out what happened in the process of new
- 2019 Shaanxi Provincial race K-variant Dijstra
猜你喜欢

LeetCode - 622 设计循环队列 (设计)

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

BPSK调制系统MATLAB仿真实现(1)
SQL cultivation manual from scratch - practical part

matlab--CVX优化工具包安装

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

Pytorch学习笔记--Pytorch常用函数总结1

Understanding the difference between wait() and sleep()

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

Box avoiding mouse
随机推荐
ML - natural language processing - Key Technologies
2019陕西省省赛J-位运算+贪心
Pytorch学习笔记--常用函数总结3
JVM parameter configuration details
Week303 of leetcode
PageHelper does not take effect, and SQL does not automatically add limit
Seata中jdbc下只有一个lib嘛?
LeetCode - 225 用队列实现栈
Endnote 添加中文GBT7714样式 word中如何引用文献
MySQL优化总结二
数据系统分区设计 - 请求路由
CF365-E - Mishka and Divisors,数论+dp
为什么PrepareStatement性能更好更安全?
No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac
2021 Shanghai match-b-ranked DP
2021 Jiangsu race a Array line segment tree, maintain value range, Euler power reduction
Submarine cable detector tss350 (I)
matlab randint,Matlab的randint函数用法「建议收藏」
C # fine sorting knowledge points 9 Set 2 (recommended Collection)
2021上海市赛-D-卡特兰数变种,dp