Skip to content

Commit 7884081

Browse files
committed
Add solution #933
1 parent ab1a77a commit 7884081

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
925|[Long Pressed Name](./0925-long-pressed-name.js)|Easy|
264264
926|[Flip String to Monotone Increasing](./0926-flip-string-to-monotone-increasing.js)|Medium|
265265
929|[Unique Email Addresses](./0929-unique-email-addresses.js)|Easy|
266+
933|[Number of Recent Calls](./0933-number-of-recent-calls.js)|Easy|
266267
966|[Vowel Spellchecker](./0966-vowel-spellchecker.js)|Medium|
267268
970|[Powerful Integers](./0970-powerful-integers.js)|Easy|
268269
976|[Largest Perimeter Triangle](./0976-largest-perimeter-triangle.js)|Easy|
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* 933. Number of Recent Calls
3+
* https://leetcode.com/problems/number-of-recent-calls/
4+
* Difficulty: Easy
5+
*
6+
* You have a RecentCounter class which counts the number of recent requests within
7+
* a certain time frame.
8+
*
9+
* Implement the RecentCounter class:
10+
* - RecentCounter() Initializes the counter with zero recent requests.
11+
* - int ping(int t) Adds a new request at time t, where t represents some time in
12+
* milliseconds, and returns the number of requests that has happened in the past
13+
* 3000 milliseconds (including the new request). Specifically, return the number
14+
* of requests that have happened in the inclusive range [t - 3000, t].
15+
*
16+
* It is guaranteed that every call to ping uses a strictly larger value of t than
17+
* the previous call.
18+
*/
19+
20+
21+
var RecentCounter = function() {
22+
this.queue = [];
23+
};
24+
25+
/**
26+
* @param {number} t
27+
* @return {number}
28+
*/
29+
RecentCounter.prototype.ping = function(t) {
30+
this.queue.push(t);
31+
while (this.queue[0] < t - 3000) {
32+
this.queue.shift();
33+
}
34+
return this.queue.length;
35+
};

0 commit comments

Comments
 (0)