具体思想:
队列直接整;
具体代码:
class HitCounter {
public:
HitCounter() {
}
void hit(int timestamp) {
que.push(timestamp);
}
int getHits(int timestamp) {
while (!que.empty()&&que.front() <= timestamp - 300) {
que.pop();
}
return que.size();
}
private:
queue<int>que;
};
/**
* Your HitCounter object will be instantiated and called as such:
* HitCounter* obj = new HitCounter();
* obj->hit(timestamp);
* int param_2 = obj->getHits(timestamp);
*/