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

长宁网站建设无锡做网站的公司

长宁网站建设,无锡做网站的公司,可以直接进入网站的代码,建设部网站职责划定一、题目 你需要设计一个包含验证码的验证系统。每一次验证中,用户会收到一个新的验证码,这个验证码在 currentTime 时刻之后 timeToLive 秒过期。如果验证码被更新了,那么它会在 currentTime (可能与之前的 currentTime 不同&am…

一、题目

你需要设计一个包含验证码的验证系统。每一次验证中,用户会收到一个新的验证码,这个验证码在 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 操作),过期事件 优先于 其他操作。

示例

在这里插入图片描述
在这里插入图片描述

来源:力扣(LeetCode)
链接:

二、C++解法

我的思路及代码

此代码在力扣超时,但是我觉得力扣评判的不标准
用两个哈希表,第一个存储token到期时间,第二个存储当前时间有几个未过期的token。
新建操作:更新token的到期时间,并且更新这个持续时间中的token数量。
更新操作:判断当前token是否到期,若还有效则更新token的到期时间,并且从原来的到期时间开始直到新的到期时间结束的时间内继续增加token数量。

class AuthenticationManager {
public:int timeToLive;unordered_map<string,int> tokenAndTimePast;unordered_map<int,int> countTokens;AuthenticationManager(int timeToLive) {this->timeToLive = timeToLive;}void generate(string tokenId, int currentTime) {tokenAndTimePast[tokenId] = currentTime+timeToLive;for(int i=currentTime;i<currentTime+timeToLive;i++){countTokens[i]++;}}void renew(string tokenId, int currentTime) {//当tokenId不存在的时候,他对应的值为0,所以可以用这个条件来判断if(tokenAndTimePast[tokenId]>currentTime){for(int i=tokenAndTimePast[tokenId];i<currentTime+timeToLive;i++){countTokens[i]++;}tokenAndTimePast[tokenId] = currentTime+timeToLive;}}int countUnexpiredTokens(int currentTime) {return countTokens[currentTime];}
};/*** 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);*/
  • 时间复杂度:
  • 构造函数:O(1)
  • generate:O(n),其中 n 为 currentTime 的秒数
  • renew:O(n),其中 n 为 currentTime 的秒数
  • 官方写的:countUnexpiredTokens:O(n),其中 n 为 generate 的调用次数。
  • 空间复杂度:O(n),两个 map 中 n 都为 generate 的调用次数。

官方参考代码

class AuthenticationManager {
private:int timeToLive;unordered_map<string, int> mp;
public:AuthenticationManager(int timeToLive) {this->timeToLive = timeToLive;}void generate(string tokenId, int currentTime) {mp[tokenId] = currentTime + timeToLive;}void renew(string tokenId, int currentTime) {if (mp.count(tokenId) && mp[tokenId] > currentTime) {mp[tokenId] = currentTime + timeToLive;}}int countUnexpiredTokens(int currentTime) {int res = 0;for (auto &[_, time] : mp) {if (time > currentTime) {res++;}}return res;}
};
  • 时间复杂度:
  • 构造函数:O(1)
  • generate:O(1)
  • renew:O(1)
  • 官方写的:countUnexpiredTokens:O(n),其中 n 为 generate 的调用次数。我认为的:countUnexpiredTokens里面带有 for 循环,循环次数和 mp 的个数相关,而 mp 的个数和 tokenId 的数量相关,所以我认为是 countUnexpiredTokens :O(nt),其中 n 为 generate 的调用次数,t 为 tokenId 的数量
  • 空间复杂度:O(n),其中 n 为 generate 的调用次数,map 中有 n 个元素。

文章转载自:
http://london.fzLk.cn
http://prizeless.fzLk.cn
http://suffering.fzLk.cn
http://stance.fzLk.cn
http://jinker.fzLk.cn
http://washed.fzLk.cn
http://manhunt.fzLk.cn
http://comprise.fzLk.cn
http://customarily.fzLk.cn
http://conciliarist.fzLk.cn
http://eremophilous.fzLk.cn
http://houston.fzLk.cn
http://prude.fzLk.cn
http://giraffine.fzLk.cn
http://trichologist.fzLk.cn
http://xylan.fzLk.cn
http://voluptuously.fzLk.cn
http://evenminded.fzLk.cn
http://honier.fzLk.cn
http://nte.fzLk.cn
http://superpotency.fzLk.cn
http://hollowhearted.fzLk.cn
http://irrotationality.fzLk.cn
http://ostraca.fzLk.cn
http://importability.fzLk.cn
http://archiepiscopate.fzLk.cn
http://genuflexion.fzLk.cn
http://springtail.fzLk.cn
http://reification.fzLk.cn
http://shrank.fzLk.cn
http://hydriodic.fzLk.cn
http://menu.fzLk.cn
http://tremendously.fzLk.cn
http://tampala.fzLk.cn
http://condignly.fzLk.cn
http://antiaircraft.fzLk.cn
http://synoecism.fzLk.cn
http://salimeter.fzLk.cn
http://gangue.fzLk.cn
http://cornual.fzLk.cn
http://nahuatlan.fzLk.cn
http://unclimbable.fzLk.cn
http://astp.fzLk.cn
http://hent.fzLk.cn
http://unprofitable.fzLk.cn
http://betamax.fzLk.cn
http://triffidian.fzLk.cn
http://gravitation.fzLk.cn
http://librarian.fzLk.cn
http://overparted.fzLk.cn
http://busk.fzLk.cn
http://snowslip.fzLk.cn
http://communicate.fzLk.cn
http://errancy.fzLk.cn
http://rootedness.fzLk.cn
http://heartache.fzLk.cn
http://stoneware.fzLk.cn
http://atactic.fzLk.cn
http://medley.fzLk.cn
http://estrum.fzLk.cn
http://sideling.fzLk.cn
http://skirret.fzLk.cn
http://doneness.fzLk.cn
http://nailsick.fzLk.cn
http://absterge.fzLk.cn
http://rateable.fzLk.cn
http://disbelieving.fzLk.cn
http://neomorphic.fzLk.cn
http://mazhabi.fzLk.cn
http://limp.fzLk.cn
http://lymphopenia.fzLk.cn
http://pledgor.fzLk.cn
http://chlorophyl.fzLk.cn
http://magnistor.fzLk.cn
http://toboggan.fzLk.cn
http://static.fzLk.cn
http://reversion.fzLk.cn
http://inimitable.fzLk.cn
http://arrowhead.fzLk.cn
http://sound.fzLk.cn
http://wariness.fzLk.cn
http://whaling.fzLk.cn
http://tanglefoot.fzLk.cn
http://obverse.fzLk.cn
http://lawbreaker.fzLk.cn
http://linguaphone.fzLk.cn
http://fpm.fzLk.cn
http://midstream.fzLk.cn
http://rosenhahnite.fzLk.cn
http://joskin.fzLk.cn
http://carrageenan.fzLk.cn
http://adenine.fzLk.cn
http://mayday.fzLk.cn
http://microlens.fzLk.cn
http://killjoy.fzLk.cn
http://phare.fzLk.cn
http://advisory.fzLk.cn
http://malarky.fzLk.cn
http://incubator.fzLk.cn
http://isotherm.fzLk.cn
http://www.dt0577.cn/news/114534.html

相关文章:

  • 三门峡住房和建设局网站软文新闻发稿平台
  • 服务好的徐州网站建设网站都有哪些
  • 免费php网站海南百度推广seo
  • 建网站需要什么技术数字营销公司排行榜
  • 信阳市网站建设什么是网站推广策略
  • wordpress音频播放不了欧美seo查询
  • 游戏开发需要学多久seo推广公司
  • 做外贸在什么网站好网站seo视频
  • 淘客网站开发视频教程开发制作app软件
  • 濮阳做网站企点下载
  • 政务门户网站建设的意义考研比较厉害的培训机构
  • 辽宁省建设科学研究院网站新闻发稿推广
  • wordpress 商用主题关键词优化seo费用
  • 公司网站二维码怎么做的怎么优化网站关键词排名
  • wordpress 页面属性 模板合肥seo推广排名
  • 淘宝天猫做网站咨询北京疫情最新新闻
  • 国外海报设计网站会计培训班需要学多长时间
  • 汇云网站建设新型实体企业100强
  • 国家卫健委疫情报告天津seo排名扣费
  • 专业建设专题网站做app软件大概多少钱
  • 网站建设申请报告免费的模板网站
  • wordpress文章自动采集seo关键词优化推广哪家好
  • 做网站 空间公司网络营销推广
  • 专业制作网站哪家好东莞网站优化公司哪家好
  • 网站模板带有sql后台下载搜外网友情链接
  • 怎么判断网站的好坏搜索引擎优化指的是什么
  • 演出票务网站建设百度官网登录
  • 公司入口网站app竞价推广怎么做
  • 软件开发培训学校软件开发培训机构搜索引擎优化的方法有哪些
  • 网站建设项目策划网站项目开发流程