class RecentCounter {
Queue<Integer> q;
public RecentCounter() {
q = new LinkedList<Integer>();
}
public int ping(int t) {
int threshold = t - 3000;
while (q.size() != 0 && q.peek() < threshold) {
q.poll();
}
q.add(t);
return q.size();
}
}
/**
* Your RecentCounter object will be instantiated and called as such:
* RecentCounter obj = new RecentCounter();
* int param_1 = obj.ping(t);
*/
原文地址:https://www.cnblogs.com/exhausttolive/p/10612535.html
时间: 2024-11-12 17:03:20