Skip to main content

🟢 剑指 Offer II 042. 最近请求次数

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解1#

class RecentCounter {
    Deque<Integer> queue;
    public RecentCounter() {        this.queue = new LinkedList<>();    }        public int ping(int t) {        this.queue.add(t);
        while (this.queue.peek() < t-3000) {            this.queue.poll();        }
        return this.queue.size();    }}
/** * Your RecentCounter object will be instantiated and called as such: * RecentCounter obj = new RecentCounter(); * int param_1 = obj.ping(t); */