当前位置:网站首页>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); */
边栏推荐
- LeetCode - 225 用队列实现栈
- Endnote 添加中文GBT7714样式 word中如何引用文献
- Cf750f1 thinking DP
- C#精挑整理知识要点11 委托和事件(建议收藏)
- ZOJ - 4114 Flipping Game-dp,合理状态表示
- matlab randint,Matlab的randint函数用法「建议收藏」
- Cf685b find the center of gravity of each subtree of a rooted tree
- 2021HNCPC-E-差分,思维
- 数据系统分区设计 - 请求路由
- Distributed principle - what is a distributed system
猜你喜欢

《图书馆管理系统——“借书还书”模块》项目研发阶段性总结

GAMES101复习:三维变换

matlab 如何保存所有运行后的数据

Pytorch学习笔记--SEResNet50搭建

CF888G-巧妙字典树+暴力分治(异或最小生成树)

MATLAB 如何生产随机复序列

Cf888g clever dictionary tree + violent divide and conquer (XOR minimum spanning tree)

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

Box avoiding mouse

伤透脑筋的CPU 上下文切换
随机推荐
ML - Speech - advanced speech model
JVM - classloader and parental delegation model
PAT甲级1153 Decode Registration Card of PAT (25 分)
HDU3873-有依赖的最短路(拓扑排序)
SVD奇异值分解推导及应用与信号恢复
ML - 语音 - 高级语音模型
C # fine sorting knowledge points 12 exception handling (recommended Collection)
Icpc2021 Kunming m-violence + chairman tree
IOS interview questions
Cf750f1 thinking DP
Graph theory and concept
Pytorch学习笔记--SEResNet50搭建
Hdu3873 shortest path with dependency (topological sorting)
JVM知识脑图分享
ML - 语音 - 传统语音模型
2021hncpc-e-difference, thinking
Pytorch学习笔记--常用函数总结3
ML - natural language processing - Introduction to natural language processing
<栈模拟递归>
Cf365-e - Mishka and divisors, number theory +dp