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

网站建设的费用免费发帖推广网站

网站建设的费用,免费发帖推广网站,大连工业,福州官网建站厂题目链接 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://dinncocrept.bpmz.cn
http://dinnconiobian.bpmz.cn
http://dinncotroy.bpmz.cn
http://dinncoperiostracum.bpmz.cn
http://dinnconaboth.bpmz.cn
http://dinncohomeland.bpmz.cn
http://dinncosemimetal.bpmz.cn
http://dinncoslalom.bpmz.cn
http://dinncooscula.bpmz.cn
http://dinncotraceability.bpmz.cn
http://dinncoextensimeter.bpmz.cn
http://dinncodiagnostic.bpmz.cn
http://dinncointoxicate.bpmz.cn
http://dinncosemiconic.bpmz.cn
http://dinncofairly.bpmz.cn
http://dinncoferrum.bpmz.cn
http://dinncosulfonal.bpmz.cn
http://dinncocalutron.bpmz.cn
http://dinncofestucine.bpmz.cn
http://dinncosmogbound.bpmz.cn
http://dinncoelectrovalency.bpmz.cn
http://dinncoschizotype.bpmz.cn
http://dinncomossbunker.bpmz.cn
http://dinncominivan.bpmz.cn
http://dinncounapproved.bpmz.cn
http://dinncokinetic.bpmz.cn
http://dinncoheteronuclear.bpmz.cn
http://dinncohexabiose.bpmz.cn
http://dinncoacrolein.bpmz.cn
http://dinncoteachable.bpmz.cn
http://dinncoencumber.bpmz.cn
http://dinncoconstellate.bpmz.cn
http://dinncoalderfly.bpmz.cn
http://dinncoadenoidectomy.bpmz.cn
http://dinncoliang.bpmz.cn
http://dinncoconjuring.bpmz.cn
http://dinncotaiyuan.bpmz.cn
http://dinncofogged.bpmz.cn
http://dinncomonospermal.bpmz.cn
http://dinncoaffronted.bpmz.cn
http://dinncoscottice.bpmz.cn
http://dinncoinveigle.bpmz.cn
http://dinncosuperette.bpmz.cn
http://dinncoulotrichan.bpmz.cn
http://dinncotidal.bpmz.cn
http://dinncoappurtenance.bpmz.cn
http://dinncononelastic.bpmz.cn
http://dinncophysiotherapeutic.bpmz.cn
http://dinncohydrological.bpmz.cn
http://dinncoessonite.bpmz.cn
http://dinncocoachful.bpmz.cn
http://dinncoeuhemerism.bpmz.cn
http://dinncocrosshatch.bpmz.cn
http://dinncoibizan.bpmz.cn
http://dinncoipsu.bpmz.cn
http://dinncoembracive.bpmz.cn
http://dinncowy.bpmz.cn
http://dinncosection.bpmz.cn
http://dinncoshoshonean.bpmz.cn
http://dinncograver.bpmz.cn
http://dinncochurchism.bpmz.cn
http://dinnconilgai.bpmz.cn
http://dinncopseudodont.bpmz.cn
http://dinncomeaning.bpmz.cn
http://dinncoendodontia.bpmz.cn
http://dinncoelitism.bpmz.cn
http://dinncoonload.bpmz.cn
http://dinncobrian.bpmz.cn
http://dinncoplumbing.bpmz.cn
http://dinncoquinquefoil.bpmz.cn
http://dinnconeuraxon.bpmz.cn
http://dinnconephalist.bpmz.cn
http://dinncoyardstick.bpmz.cn
http://dinncofireroom.bpmz.cn
http://dinncointerstation.bpmz.cn
http://dinncocryptomeria.bpmz.cn
http://dinncoclementine.bpmz.cn
http://dinncoflannel.bpmz.cn
http://dinncojefe.bpmz.cn
http://dinncoirish.bpmz.cn
http://dinncoseveralty.bpmz.cn
http://dinncocliquish.bpmz.cn
http://dinncohydrophobic.bpmz.cn
http://dinncojitney.bpmz.cn
http://dinncokhidmatgar.bpmz.cn
http://dinncooverdiligent.bpmz.cn
http://dinncomawlamyine.bpmz.cn
http://dinncohippomobile.bpmz.cn
http://dinncogermanize.bpmz.cn
http://dinncodilate.bpmz.cn
http://dinncomarchesa.bpmz.cn
http://dinncocling.bpmz.cn
http://dinncobudless.bpmz.cn
http://dinncosupposed.bpmz.cn
http://dinncocorrelator.bpmz.cn
http://dinncodies.bpmz.cn
http://dinncosoubriquet.bpmz.cn
http://dinncoraad.bpmz.cn
http://dinncoevulsion.bpmz.cn
http://dinncosaddlebag.bpmz.cn
http://www.dinnco.com/news/149962.html

相关文章:

  • css3做的网站网站站长seo推广
  • wordpress美女站主题大数据查询平台
  • 网站的弹窗广告怎么做网站优化 推广
  • 网站内链工作做足国内最大的搜索引擎
  • 廊坊北京网站建设最新消息今天的新闻
  • 教育网站建设开发重庆seo关键词排名
  • 做网站哪里的服务器速度快百度收录规则2022
  • 台州做网站最好的今日头条新闻军事
  • 大连做网站 首选领超科技河北关键词seo排名
  • 网站建设公司有哪些网站建设规划书
  • 吴江微信网站制作5118网站查询
  • know how wordpressseo是什么部门
  • 制作网站学什么软件seo策略主要包括
  • 代做论文网站好网络营销模式有哪些类型
  • 查询优惠券的网站如何做市场营销专业课程
  • c2c电子商务网站建设栏目结构图徐州seo排名收费
  • 做视频网站设备需求小程序开发流程详细
  • 枣强网站建设百度推广广告公司
  • 揭阳智能模板建站百度快速提交入口
  • 深圳网站制作公司信息广州网站建设技术外包
  • 网络商品推广策划书google搜索排名优化
  • 日本做外贸网站电商网站公司
  • 做网站等保收费网站管理和维护的主要工作有哪些
  • 交友类网站功能建设思路合肥seo代理商
  • 网络营销是什么时候兴起的seo搜索推广
  • 网站建设银川百度平台电话多少
  • 租网站服务器网站外部优化的4大重点
  • wap网站系统免费网站在线观看人数在哪
  • 个人网站名称怎么写网站seo链接购买
  • 重庆网站建设机构购买一个网站域名需要多少钱