933. 最近的请求次数
解法一:队列
维护一个队列,每次插入时,都把队列头部超时的删掉,最后返回队列长度即可。
var RecentCounter = function () {
this.pingList = [];
};
/**
* @param {number} t
* @return {number}
*/
RecentCounter.prototype.ping = function (t) {
this.pingList.push(t);
while (t - this.pingList[0] > 3000) {
this.pingList.shift();
}
return this.pingList.length;
};
/**
* Your RecentCounter object will be instantiated and called as such:
* var obj = new RecentCounter()
* var param_1 = obj.ping(t)
*/