老师不知道为什么提示“超出时间限制”
来源:4-3 LeetCode:933. 最近的请求次数

weixin_慕丝2377090
2021-08-28
var RecentCounter = function() {
this.q = [];
};
/**
* @param {number} t
* @return {number}
*/
RecentCounter.prototype.ping = function(t) {
this.q.push(t);
const p = this.q[0];
while(t - p > 3000){//这里直接用this.q[0]就不会有问题
this.q.shift();
}
return this.q.length;
};
/**
* Your RecentCounter object will be instantiated and called as such:
* var obj = new RecentCounter()
* var param_1 = obj.ping(t)
*/
写回答
1回答
-
shift之后队头变了,你用p的话,指向的还是老队头
012021-08-28
相似问题