-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
/
Copy pathSolution.go
37 lines (32 loc) · 911 Bytes
/
Solution.go
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
type AuthenticationManager struct {
t int
d map[string]int
}
func Constructor(timeToLive int) AuthenticationManager {
return AuthenticationManager{timeToLive, map[string]int{}}
}
func (this *AuthenticationManager) Generate(tokenId string, currentTime int) {
this.d[tokenId] = currentTime + this.t
}
func (this *AuthenticationManager) Renew(tokenId string, currentTime int) {
if v, ok := this.d[tokenId]; !ok || v <= currentTime {
return
}
this.Generate(tokenId, currentTime)
}
func (this *AuthenticationManager) CountUnexpiredTokens(currentTime int) int {
ans := 0
for _, exp := range this.d {
if exp > currentTime {
ans++
}
}
return ans
}
/**
* Your AuthenticationManager object will be instantiated and called as such:
* obj := Constructor(timeToLive);
* obj.Generate(tokenId,currentTime);
* obj.Renew(tokenId,currentTime);
* param_3 := obj.CountUnexpiredTokens(currentTime);
*/