forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cpp
33 lines (28 loc) · 852 Bytes
/
Solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class AuthenticationManager {
public:
AuthenticationManager(int timeToLive) {
t = timeToLive;
}
void generate(string tokenId, int currentTime) {
d[tokenId] = currentTime + t;
}
void renew(string tokenId, int currentTime) {
if (d[tokenId] <= currentTime) return;
generate(tokenId, currentTime);
}
int countUnexpiredTokens(int currentTime) {
int ans = 0;
for (auto& [_, v] : d) ans += v > currentTime;
return ans;
}
private:
int t;
unordered_map<string, int> d;
};
/**
* Your AuthenticationManager object will be instantiated and called as such:
* AuthenticationManager* obj = new AuthenticationManager(timeToLive);
* obj->generate(tokenId,currentTime);
* obj->renew(tokenId,currentTime);
* int param_3 = obj->countUnexpiredTokens(currentTime);
*/