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

淄博网站制作高端营销wordpress七牛云图床

淄博网站制作高端营销,wordpress七牛云图床,wordpress 侧 悬浮插件,淄博seo排名TinyURL 是一种 URL 简化服务#xff0c; 比如#xff1a;当你输入一个 URL https://leetcode.com/problems/design-tinyurl 时#xff0c;它将返回一个简化的URL http://tinyurl.com/4e9iAk 。请你设计一个类来加密与解密 TinyURL 。 加密和解密算法如何设计和运作是没有限…TinyURL 是一种 URL 简化服务 比如当你输入一个 URL https://leetcode.com/problems/design-tinyurl 时它将返回一个简化的URL http://tinyurl.com/4e9iAk 。请你设计一个类来加密与解密 TinyURL 。 加密和解密算法如何设计和运作是没有限制的你只需要保证一个 URL 可以被加密成一个 TinyURL 并且这个 TinyURL 可以用解密方法恢复成原本的 URL 。 实现 Solution 类 Solution() 初始化 TinyURL 系统对象。 String encode(String longUrl) 返回 longUrl 对应的 TinyURL 。 String decode(String shortUrl) 返回 shortUrl 原本的 URL 。题目数据保证给定的 shortUrl 是由同一个系统对象加密的。 示例 输入url “https://leetcode.com/problems/design-tinyurl” 输出“https://leetcode.com/problems/design-tinyurl” 解释 Solution obj new Solution(); string tiny obj.encode(url); // 返回加密后得到的 TinyURL 。 string ans obj.decode(tiny); // 返回解密后得到的原本的 URL 。 提示 1 url.length 104 题目数据保证 url 是一个有效的 URL 解法一可将长url存入数据库中id为自增主键每次存放后会得到数据库中一个自增长的id然后将带有该id的url作为短url class Solution { public:Solution () {id 0;}// Encodes a URL to a shortened URL.string encode(string longUrl) {db[id] longUrl;string shortUrl string(http://tinyurl.com/) to_string(id);id;return shortUrl;}// Decodes a shortened URL to its original URL.string decode(string shortUrl) {int idStartIdx shortUrl.rfind(/) 1;int id stoi(shortUrl.substr(idStartIdx, shortUrl.size() - idStartIdx));return db[id];}private:int id;unordered_mapint, string db; };// Your Solution object will be instantiated and called as such: // Solution solution; // solution.decode(solution.encode(url));如果长url的长度为n此算法中encode方法的时间复杂度为On空间复杂度为Ondecode方法的时间复杂度为O1空间复杂度为O1。 解法二哈希生成选两个合适的质数k1_11​1117k2_22​109^997使用以下方法计算长url的哈希值 然后encode函数将哈希值和长url存入数据库并返回含有哈希值的短url。decode函数可根据短url中的哈希值从数据库中取出长url。 当发生哈希冲突时采用线性探测再散列的方法将key加1直到没有冲突。相同的长url的哈希值相同哈希冲突可能会频繁发生为避免这一点我们使用一个额外的哈希表记录从长url到哈希值的映射。 const long long k1 1117; const long long k2 1e9 7;class Solution { public:// Encodes a URL to a shortened URL.string encode(string longUrl) {if (urlToKey[longUrl] 0) {return string(http://tinyurl.com/) to_string(urlToKey[longUrl]);}int key 0, base 1;for (char c : longUrl) {int key (key c * base) % k2;int base (base * k1) % k2;}while (db.find(key) ! db.end()) {key (key 1) % k2;}db[key] longUrl;return string(http://tinyurl.com/) to_string(key);}// Decodes a shortened URL to its original URL.string decode(string shortUrl) {int idStartIdx shortUrl.rfind(/) 1;int id stoi(shortUrl.substr(idStartIdx, shortUrl.size() - idStartIdx));return db[id];}private:unordered_mapint, string db;unordered_mapstring, int urlToKey; };// Your Solution object will be instantiated and called as such: // Solution solution; // solution.decode(solution.encode(url));如果长url的长度为n此算法中encode方法的时间复杂度为On在数据量远小于10e97的情况下哈希冲突很少发生空间复杂度为Ondecode方法的时间复杂度为O1空间复杂度为O1。 计算字符串的哈希时类似于计算一个数字如1234它等于1 * 10³ 2 * 10² 3 * 10 4 * 1。 解法三随机生成随机生成一个key如果key已存在则继续生成直到出现不存在的key class Solution { public:// Encodes a URL to a shortened URL.string encode(string longUrl) {default_random_engine e(time(0));uniform_int_distributionint u(0, INT_MAX);int key u(e);while (db.find(key) ! db.end()) {key u(e);}db[key] longUrl;return string(http://tinyurl.com/) to_string(key);}// Decodes a shortened URL to its original URL.string decode(string shortUrl) {int idStartIdx shortUrl.rfind(/) 1;int id stoi(shortUrl.substr(idStartIdx, shortUrl.size() - idStartIdx));return db[id];}private:unordered_mapint, string db; };// Your Solution object will be instantiated and called as such: // Solution solution; // solution.decode(solution.encode(url));如果长url的长度为n此算法中encode方法的时间复杂度为On空间复杂度为Ondecode方法的时间复杂度为O1空间复杂度为O1。
http://www.w-s-a.com/news/986051/

相关文章:

  • 陕西营销型手机网站建设深圳制作网站服务
  • 受欢迎的锦州网站建设Wordpress 图片左右滑动
  • 湖南优化网站建设线上网站建设需求
  • 建什么类型的网站访问量比较大哪些外包公司比较好
  • php网站地图外贸建站哪家强外贸网站怎么做
  • 宁波五金网站建设中国建筑网官网投诉查询
  • 哪个网站注册域名便宜免费流程图制作网站
  • 潍坊做网站南宁网站seo优化公司
  • 网站建设的基本技术步骤无网站营销
  • 我国旅游网站的建设网站开发 混合式 数据库
  • 淘宝客网站域名家居网站开发项目计划书
  • 网站打不开显示asp苏州注册公司需要多少钱
  • 凡科建站登录官网wordpress主题有什么用
  • 西安双语网站建设怎么做网页动图
  • 宝安自适应网站建设无锡新区企业网站推广
  • 肇庆建设局网站cpanel 安装wordpress
  • 长春启做网站多少怎样换wordpress域名
  • 山西网站建设情况汇总vs2010 c 建设网站
  • 网站推广策划书 精品深圳市住建局和建设局官网
  • 住房和城乡建设部干部学院网站一般做公司网站需要哪几点
  • 网站制作流程详解(学做网站第一步)免费个人网站模版ps
  • 狮山网站建设公司微信平台软件开发
  • 绥芬河网站建设学网站开发的能找什么工作
  • 网站域名申请之后如何做网站微信公众号网页版登录入口
  • 网站优化图片省级精品课程网站
  • 婚纱摄影的网站模板怎么做网站自己当站长
  • 江西建设部网站wordpress弹出式广告
  • 工商年检在哪个网站做中国建设银行个人登录
  • seo做网站郑州巩义网站建设
  • 建设银行网站机构特点业务发展网站推广工作计划