[LeetCode] 933. Number of Recent Calls

0

LeetCode

목록 보기
38/58
post-thumbnail

[LeetCode] 933. Number of Recent Calls

풀이

#include <queue>
#include <algorithm>

class RecentCounter {
public:
    queue<int> requests;

    RecentCounter() {
      requests = queue<int>();
    }
    
    int ping(int t) {
        requests.push(t);
        while((!requests.empty()) && (requests.front() < t - 3000)) requests.pop();
        return requests.size();
    }
};

/**
 * Your RecentCounter object will be instantiated and called as such:
 * RecentCounter* obj = new RecentCounter();
 * int param_1 = obj->ping(t);
 */
profile
Be able to be vulnerable, in search of truth

0개의 댓글