Leetcode学习笔记:#933. Number of Recent Calls
作者:互联网
Leetcode学习笔记:933. Number of Recent Calls
Write a class RecentCounter to count recent requests.
It has only one method: ping(int t), where t represents some time in milliseconds.
Return the number of pings that have been made from 3000 milliseconds ago until now.
Any ping with time in [t - 3000, t] will count, including the current ping.
It is guaranteed that every call to ping uses a strictly larger value of t than before.
实现:
Queue<Integer> q;
public RecentCounter() {
q = new LinkedList<>();
}
public int ping(int t) {
q.offer(t);
while (q.peek() < t - 3000) { q.poll(); }
return q.size();
}
标签:Calls,int,ping,Number,public,RecentCounter,3000,933,Leetcode 来源: https://blog.csdn.net/ccystewart/article/details/90178612