【LeetCode刷题-队列】--933.最近的请求次数

933.最近的请求次数

【LeetCode刷题-队列】--933.最近的请求次数_第1张图片

class RecentCounter {

    Queue<Integer> queue = new LinkedList<>();
    public RecentCounter() {

    }
    
    public int ping(int t) {
        queue.offer(t);
        while(t - queue.peek() > 3000){
            queue.poll();
        }
        return queue.size();
    }
}

/**
 * Your RecentCounter object will be instantiated and called as such:
 * RecentCounter obj = new RecentCounter();
 * int param_1 = obj.ping(t);
 */

你可能感兴趣的:(#,队列与栈,leetcode,算法)