Shu-How Zの小窝

Loading...

LeetCode:933.最近的请求次数


var RecentCounter = function() {
    this.queue=[]
};

/** 
 * @param {number} t
 * @return {number}
 */
RecentCounter.prototype.ping = function(t) {
    this.queue.push(t)
    while(this.queue[0]<t-3000){
        this.queue.shift()
    }
    return this.queue.length;
};

/** 
 * Your RecentCounter object will be instantiated and called as such:
 * var obj = new RecentCounter()
 * var param_1 = obj.ping(t)
 */
posted @ 2025-01-10 14:31  KooTeam  阅读(19)  评论(0)    收藏  举报