leetcode 1797
题目描述
1797. 设计一个验证系统
你需要设计一个包含验证码的验证系统。每一次验证中,用户会收到一个新的验证码,这个验证码在 currentTime 时刻之后 timeToLive 秒过期。如果验证码被更新了,那么它会在 currentTime (可能与之前的 currentTime 不同)时刻延长 timeToLive 秒。
请你实现 AuthenticationManager 类:
AuthenticationManager(int timeToLive)构造AuthenticationManager并设置timeToLive参数。generate(string tokenId, int currentTime)给定tokenId,在当前时间currentTime生成一个新的验证码。renew(string tokenId, int currentTime)将给定tokenId且 未过期 的验证码在currentTime时刻更新。如果给定tokenId对应的验证码不存在或已过期,请你忽略该操作,不会有任何更新操作发生。countUnexpiredTokens(int currentTime)请返回在给定currentTime时刻,未过期 的验证码数目。
如果一个验证码在时刻 t 过期,且另一个操作恰好在时刻 t 发生(renew 或者 countUnexpiredTokens 操作),过期事件 优先于 其他操作。
示例 1:

1 | |
解题思路
- 按部就班,主要就是看过期时间和当前时间的关系,没啥意思
执行用时:51 ms, 在所有 Java 提交中击败了68.23%的用户
内存消耗:42.6 MB, 在所有 Java 提交中击败了85.88%的用户
通过测试用例:90 / 90
时间 O(N)
空间 O(N)
1 | |
leetcode 1797
https://kkkkkong.github.io/posts/2315.html