var RecentCounter = function () {
this.queue = []
};
RecentCounter.prototype.ping = function (t) {
this.queue.push(t)
let beforeT = t - 3000
while (this.queue[0] < beforeT) {
this.queue.shift()
}
return this.queue.length
};
时间复杂度:O(n)
空间复杂度:O(n)