# 933. Number of Recent Calls [933. Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) (<font color="#00AF9B"> Easy</font> 通過率: 76.6%) ## 限制條件 <ul> <li>1 <= t <= 10^9</li> <li>Each test case will call ping with strictly increasing values of t.</li> <li>At most 104 calls will be made to ping.</li> </ul> ### 解法 1 糊里糊塗就過了,實在不好講怎麼過的(誤 不過重點是 queue 的使用方式,這裡使用 deque 是因為只有最前面跟最後面會用到,所以使用 deque 會比較方便 - 時間複雜度: O(N) - 空間複雜度: O(N) ```cpp!= class RecentCounter { deque<int> pingList; public: RecentCounter() { } int ping(int t) { pingList.push_back(t); while (t - pingList.front() > 3000) { pingList.pop_front(); } return pingList.size(); } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up