Leetcode算法题1701-1800


1701-1710

1711-1720

1721-1730

1731-1740

1741-1750

1751-1760

1761-1770

1771-1780

1781-1790

1791-1800

1797.设计一个验证系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class AuthenticationManager {
public:
int timeToLive;
unordered_map<string, int> map;

AuthenticationManager(int timeToLive) : timeToLive(timeToLive) {}

void generate(string tokenId, int currentTime) {
map[tokenId] = currentTime;
}

void renew(string tokenId, int currentTime) {
if (map.find(tokenId) != map.end() && currentTime < map[tokenId] + timeToLive) map[tokenId] = currentTime;
}

int countUnexpiredTokens(int currentTime) {
int cnt = 0;
for (auto &[token, time]: map) {
if (time + timeToLive > currentTime) cnt += 1;
}
return cnt;
}
};

文章作者: 不二
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 不二 !
  目录