好不容易遇到一个简单的题,就不过多解释了,这个题只有能理解,写代码也是麻溜的很,只需要好好理解题目就行
/*
* @lc app=leetcode.cn id=933 lang=javascript
*
*
*/
// @lc code=start
var RecentCounter = function () {
this.arr = [];
};
/**
* @param {number} t
* @return {number}
*/
RecentCounter.prototype.ping = function (t) {
this.arr.push(t);
while (this.arr[0] < t - 3000) {
this.arr.shift();
}
return this.arr.length;
};
/**
* Your RecentCounter object will be instantiated and called as such:
* var obj = new RecentCounter()
* var param_1 = obj.ping(t)
*/
// @lc code=end