当前位置:网站首页>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); */
边栏推荐
猜你喜欢

Games101 review: linear algebra

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

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

ML - 语音 - 传统语音模型

MySQL—用户和权限管控

SVD奇异值分解推导及应用与信号恢复

ML - natural language processing - Introduction to natural language processing

p4552-差分

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

P4552 differential
随机推荐
The difference between Apple buy in and apple pay
2021上海市赛-B-排序后dp
MySQL optimization summary II
IOS interview questions
JVM garbage collector details
MATLAB 如何生产随机复序列
Distributed principle - what is a distributed system
ML - natural language processing - Basics
CF365-E - Mishka and Divisors,数论+dp
Games101 review: Transformation
Application of C language array in Sanzi chess -- prototype of Queen n problem
JVM parameter configuration details
伤透脑筋的CPU 上下文切换
2021 Jiangsu race a Array line segment tree, maintain value range, Euler power reduction
JS URLEncode function
Flex 布局
Box avoiding mouse
小波变换--dwt2 与wavedec2
2021 Shanghai match-h-two point answer
2021上海市赛-H-二分答案