1701-1710¶
1711-1720¶
1721-1730¶
1731-1740¶
1741-1750¶
1751-1760¶
1761-1770¶
1771-1780¶
1781-1790¶
1791-1800¶
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;
}
};