Skip to content

Commit 66b6b80

Browse files
committed
Time: 29 ms (94.88%), Space: 61.9 MB (76.41%) - LeetHub
1 parent 914b058 commit 66b6b80

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
var RecentCounter = function() {
3+
this.storage = [];
4+
};
5+
6+
/**
7+
* @param {number} t
8+
* @return {number}
9+
*/
10+
RecentCounter.prototype.ping = function(t) {
11+
while (this.storage.length && this.storage[0] < t - 3000) {
12+
this.storage.shift();
13+
}
14+
this.storage.push(t);
15+
return this.storage.length;
16+
};
17+
18+
/**
19+
* Your RecentCounter object will be instantiated and called as such:
20+
* var obj = new RecentCounter()
21+
* var param_1 = obj.ping(t)
22+
*/

0 commit comments

Comments
 (0)