Leetcode#933. Number of Recent Calls
Problem
You have a RecentCounter class which counts the number of recent requests within a certain time frame.
Implement the RecentCounter class:
RecentCounter()Initializes the counter with zero recent requests.int ping(int t)Adds a new request at timet, wheretrepresents some time in milliseconds, and returns the number of requests that has happened in the past3000milliseconds (including the new request). Specifically, return the number of requests that have happened in the inclusive range[t - 3000, t].
It is guaranteed that every call to ping uses a strictly larger value of t than the previous call.
Example 1:
1 | Input |
Constraints:
1 <= t <= 10^9- Each test case will call
pingwith strictly increasing values oft. - At most
10^4calls will be made toping.
Solve
做一個容器
每當Ping時放進新的
並檢查 最前面超出範圍 pop掉
1 | class RecentCounter: |
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Imisky!
評論
