1.本题及其迷糊!!!
2.经过我这个菜逼看了无数次题解,终于有一丢丢眉头了
3.本题的意识就是在给定的时间段的请求次数,它会更新请求;
4.我们用队列来存储,因为是先进先出嘛,完全符合题意
5.加入队列后,我们取出队列的第一个值,对比t-3000,如果前者大就啥也不干,因为这个元素符合题意,不用淘汰,小于的时候就不行了,这个请求就已经过期了,要出队列,poll()掉;
class RecentCounter {
Queue<Integer> dui=new LinkedList();
public RecentCounter() {
}
public int ping(int t) {
dui.add(t);
while(dui.peek()<t-3000){
dui.poll();
}
return dui.size();
}
}