Created
November 9, 2018 14:00
-
-
Save fpdjsns/40262372506889ff5cfdfc8e6e8826a5 to your computer and use it in GitHub Desktop.
[leetcode] 933. Number of Recent Calls : https://leetcode.com/problems/number-of-recent-calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RecentCounter { | |
public: | |
queue<int> q = queue<int>(); | |
RecentCounter() { | |
q = queue<int>(); | |
} | |
int ping(int t) { | |
q.push(t); | |
while(!q.empty() && q.front() < t-3000) q.pop(); | |
return q.size(); | |
} | |
}; | |
/** | |
* Your RecentCounter object will be instantiated and called as such: | |
* RecentCounter* obj = new RecentCounter(); | |
* int param_1 = obj->ping(t); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment