image_2021-11-22_18-01-53.png
45.3 KB
#N933. Number of Recent Calls
problem link
#solution
problem link
#solution
class RecentCounter {
Queue<Integer> queue = new LinkedList<>();
public RecentCounter() {
}
public int ping(int t) {
while(!queue.isEmpty() && queue.peek()<t-3000) queue.remove();
queue.add(t);
return queue.size();
}
}