// Principalmente porque el significado del título no es fácil de entender
class RecentCounter {
// 定义队列
Queue<Integer> q;
public RecentCounter() {
q = new LinkedList();
}
public int ping(int t) {
q.add(t);
// 判断t-3000的起始位置,不满足条件的弹出
while(q.peek()<t-3000)
q.poll();
// 满足条件的直接计算队列长度即可
return q.size();
}
}
/**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter obj = new RecentCounter();
* int param_1 = obj.ping(t);
*/