-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
/
Copy pathSolution.java
37 lines (32 loc) · 995 Bytes
/
Solution.java
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
34
35
36
37
class AuthenticationManager {
private int t;
private Map<String, Integer> d = new HashMap<>();
public AuthenticationManager(int timeToLive) {
t = timeToLive;
}
public void generate(String tokenId, int currentTime) {
d.put(tokenId, currentTime + t);
}
public void renew(String tokenId, int currentTime) {
if (d.getOrDefault(tokenId, 0) <= currentTime) {
return;
}
generate(tokenId, currentTime);
}
public int countUnexpiredTokens(int currentTime) {
int ans = 0;
for (int exp : d.values()) {
if (exp > currentTime) {
++ans;
}
}
return ans;
}
}
/**
* 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);
*/