File tree 2 files changed +36
-0
lines changed
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 263
263
925|[ Long Pressed Name] ( ./0925-long-pressed-name.js ) |Easy|
264
264
926|[ Flip String to Monotone Increasing] ( ./0926-flip-string-to-monotone-increasing.js ) |Medium|
265
265
929|[ Unique Email Addresses] ( ./0929-unique-email-addresses.js ) |Easy|
266
+ 933|[ Number of Recent Calls] ( ./0933-number-of-recent-calls.js ) |Easy|
266
267
966|[ Vowel Spellchecker] ( ./0966-vowel-spellchecker.js ) |Medium|
267
268
970|[ Powerful Integers] ( ./0970-powerful-integers.js ) |Easy|
268
269
976|[ Largest Perimeter Triangle] ( ./0976-largest-perimeter-triangle.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments