这么写貌似不对
来源:4-3 LeetCode:933. 最近的请求次数

vZina
2021-05-29
[“RecentCounter”,“ping”,“ping”,“ping”,“ping”,“ping”]
[[],[1],[100],[3001],[3002],[6666]]
输出的是 [null,1,2,3,3,3]
预期的是 [null,1,2,3,3,1]
非要用队列,写个递归
var RecentCounter = function() {
this.q = [];
};
/**
* @param {number} t
* @return {number}
*/
RecentCounter.prototype.ping = function(t) {
this.q.push(t);
let shiftFn = () => {
if(this.q[0] >= t - 3000) return;
this.q.shift();
shiftFn()
}
shiftFn();
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回答
-
lewis
2021-05-29
你的问题是啥
032023-09-28
相似问题