当前位置: 首页 > news >正文

做网站推广怎么样网页设计流程的四个阶段

做网站推广怎么样,网页设计流程的四个阶段,房地产公司名称大全,网站建设z亿玛酷1负责题目链接 Leetcode.1797 设计一个验证系统 Rating : 1534 题目描述 你需要设计一个包含验证码的验证系统。每一次验证中,用户会收到一个新的验证码,这个验证码在 currentTime时刻之后 timeToLive秒过期。如果验证码被更新了,那么它会在 curr…

题目链接

Leetcode.1797 设计一个验证系统 Rating : 1534

题目描述

你需要设计一个包含验证码的验证系统。每一次验证中,用户会收到一个新的验证码,这个验证码在 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:

在这里插入图片描述

输入:
[“AuthenticationManager”, “renew”, “generate”, “countUnexpiredTokens”, “generate”, “renew”, “renew”, “countUnexpiredTokens”]
[[5], [“aaa”, 1], [“aaa”, 2], [6], [“bbb”, 7], [“aaa”, 8], [“bbb”, 10], [15]]
输出:
[null, null, null, 1, null, null, null, 0]
解释:
AuthenticationManager authenticationManager = new AuthenticationManager(5); // 构造 AuthenticationManager ,设置 timeToLive = 5 秒。
authenticationManager.renew(“aaa”, 1); // 时刻 1 时,没有验证码的 tokenId 为 “aaa” ,没有验证码被更新。
authenticationManager.generate(“aaa”, 2); // 时刻 2 时,生成一个 tokenId 为 “aaa” 的新验证码。
authenticationManager.countUnexpiredTokens(6); // 时刻 6 时,只有 tokenId 为 “aaa” 的验证码未过期,所以返回 1 。
authenticationManager.generate(“bbb”, 7); // 时刻 7 时,生成一个 tokenId 为 “bbb” 的新验证码。
authenticationManager.renew(“aaa”, 8); // tokenId 为 “aaa” 的验证码在时刻 7 过期,且 8 >= 7 ,所以时刻 8 的renew 操作被忽略,没有验证码被更新。
authenticationManager.renew(“bbb”, 10); // tokenId 为 “bbb” 的验证码在时刻 10 没有过期,所以 renew 操作会执行,该 token 将在时刻 15 过期。
authenticationManager.countUnexpiredTokens(15); // tokenId 为 “bbb” 的验证码在时刻 15 过期,tokenId 为 “aaa” 的验证码在时刻 7 过期,所有验证码均已过期,所以返回 0 。

提示:

  • 1<=timeToLive<=1081 <= timeToLive <= 10^81<=timeToLive<=108
  • 1<=currentTime<=1081 <= currentTime <= 10^81<=currentTime<=108
  • 1<=tokenId.length<=51 <= tokenId.length <= 51<=tokenId.length<=5
  • tokenId只包含小写英文字母
  • 所有 generate函数的调用都会包含独一无二的 tokenId值。
  • 所有函数调用中,currentTime的值 严格递增
  • 所有函数的调用次数总共不超过 2000次。

分析:

用一个 哈希表 key代表验证码,value代表过期时间进行模拟即可。

时间复杂度:O(1)O(1)O(1)

代码:

class AuthenticationManager {
public:int timeToLive;unordered_map<string,int> m;AuthenticationManager(int timeToLive) {this->timeToLive  = timeToLive;}void generate(string tokenId, int currentTime) {m[tokenId] = currentTime + timeToLive;}void renew(string tokenId, int currentTime) {//先去掉已经过期的验证码for(auto it = m.begin();it != m.end();){if(it->second <= currentTime) m.erase(it++);else it++;}//再更新if(m.count(tokenId)) m[tokenId] = currentTime + timeToLive;}int countUnexpiredTokens(int currentTime) {int ans = 0;for(auto [k,v]:m){//记录未过期的验证码数量if(v > 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);*/
http://www.yayakq.cn/news/365572/

相关文章:

  • 南昌做网站价格自己建网站怎么推广
  • 万网 速成网站网站建设制作模板网站怎么做
  • 网站特效网站的信息管理建设的必要性
  • 沂水网站设计锡盟做网站
  • 深圳较便宜的网站建设微信小程序
  • 网站建设专家北京注安产品设计方案怎么写
  • 网站框架结构图效果图网站有哪些好的
  • 代做设计的网站网站技能培训机构
  • 网站推荐2021邢台网站建设 冀icp备
  • 网站改版制作智效云seo
  • 如何做织梦论坛类的网站重庆竣工验收备案网上查询
  • 网站建设优化服务好么宁夏网站seo
  • 在线教育网站建设投标书下载app软件安装手机上
  • 郑州高新区做网站的公司wordpress文字轮播
  • c 能用来做网站吗企业网站建设方案模板
  • 免版权图片网站wordpress为什么感觉加载慢
  • 福建微网站建设价格附近室内设计培训学校
  • 网站域名备案变更意大利天天电信app下载
  • 做个淘宝客网站怎么做的紧急通知河南全省暂停
  • 海洋网络做网站不负责大连零基础网站建设培训哪里有
  • 山东青岛网站设计公司linux 下载wordpress
  • 扁平化颜色网站企业微网站制作教程
  • 企划做网站网站内容的设计
  • 智能模板网站建设南江县规划和建设局网站
  • 网站被k后是怎样的邯郸网站制作费用
  • 网站开发选择题亚马逊推广
  • 池州网站开发界面设计是做什么的
  • 旅游网站的系统建设的意义做爰动态视频网站
  • 打鱼跟电子游戏网站怎么做wordpress文本块表格
  • 上海浦东做网站的公司昆明网站建设首选才力