933. Number of Recent Calls Easy
1/**
2 * [933] Number of Recent Calls
3 *
4 * You have a RecentCounter class which counts the number of recent requests within a certain time frame.
5 * Implement the RecentCounter class:
6 *
7 * RecentCounter() Initializes the counter with zero recent requests.
8 * int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, and returns the number of requests that has happened in the past 3000 milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range [t - 3000, t].
9 *
10 * It is guaranteed that every call to ping uses a strictly larger value of t than the previous call.
11 *
12 * Example 1:
13 *
14 * Input
15 * ["RecentCounter", "ping", "ping", "ping", "ping"]
16 * [[], [1], [100], [3001], [3002]]
17 * Output
18 * [null, 1, 2, 3, 3]
19 * Explanation
20 * RecentCounter recentCounter = new RecentCounter();
21 * recentCounter.ping(1); // requests = [<u>1</u>], range is [-2999,1], return 1
22 * recentCounter.ping(100); // requests = [<u>1</u>, <u>100</u>], range is [-2900,100], return 2
23 * recentCounter.ping(3001); // requests = [<u>1</u>, <u>100</u>, <u>3001</u>], range is [1,3001], return 3
24 * recentCounter.ping(3002); // requests = [1, <u>100</u>, <u>3001</u>, <u>3002</u>], range is [2,3002], return 3
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= t <= 10^9
30 * Each test case will call ping with strictly increasing values of t.
31 * At most 10^4 calls will be made to ping.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/number-of-recent-calls/
37// discuss: https://leetcode.com/problems/number-of-recent-calls/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41struct RecentCounter {
42 vec![]
43 }
44
45
46/**
47 * `&self` means the method takes an immutable reference.
48 * If you need a mutable reference, change it to `&mut self` instead.
49 */
50impl RecentCounter {
51
52 fn new() -> Self {
53
54 }
55
56 fn ping(&self, t: i32) -> i32 {
57
58 }
59}
60
61/**
62 * Your RecentCounter object will be instantiated and called as such:
63 * let obj = RecentCounter::new();
64 * let ret_1: i32 = obj.ping(t);
65 */
66
67// submission codes end
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn test_933() {
75 }
76}
77
Back
© 2025 bowen.ge All Rights Reserved.