首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏搬砖记录

    49 Encode and Decode TinyURL

    TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl Design the encode and decode methods for the TinyURL service. 分析 题意:设计一个简化URL的编码算法,比如 将https://leetcode.com/problems/design-tinyurl编码为http://tinyurl.com/4e9iAk, 当然http://tinyurl.com/4e9iAk解码的结果也为https://leetcode.com/problems/design-tinyurl。 以https://leetcode.com/problems/design-tinyurl为例,个人觉得难点有两点: 1.xxx/design-tinyurl和xxx/design-tinyuri也应当被识别

    91820发布于 2021-08-18
  • 来自专栏码匠的流水账

    聊聊base62与tinyURL

    Design TinyURL 如何设计短网址系统(TinyURL)

    2.1K20发布于 2018-09-17
  • 来自专栏曌的晓痴

    LeetCode - TinyURL的加密与解密

    TinyURL是一种URL简化服务, 比如:当你输入一个URL https://leetcode.com/problems/design-tinyurl 时,它将返回一个简化的URL http://tinyurl.com 要求:设计一个 TinyURL 的加密 encode 和解密 decode 的方法。 你的加密和解密算法如何设计和运作是没有限制的,你只需要保证一个URL可以被加密成一个TinyURL,并且这个TinyURL可以用解密方法恢复成原本的URL。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/encode-and-decode-tinyurl 著作权归领扣网络所有。 但是这种算法很明显我一时之间想不出来,所以我就想了个笨办法,用Base64加解密...建议参考如下的题解 中文官网题解: https://leetcode-cn.com/problems/encode-and-decode-tinyurl

    1.1K20发布于 2019-08-13
  • 来自专栏眯眯眼猫头鹰的小树杈

    Encode and Decode TinyURL

    题目要求 Note: This is a companion problem to the System Design problem:Design TinyURL-System/). TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design the encode and decode methods for the TinyURL service. String> shortToLongUrl = new HashMap<>(); private static final String SHORT\_URL\_PREFIX \= "http://tinyurl.com

    49820发布于 2020-05-12
  • 来自专栏Michael阿明学习之路

    TinyURL 的加密与解密(哈希)

    题目信息 TinyURL是一种URL简化服务, 比如:当你输入一个URL https://leetcode.com/problems/design-tinyurl 时,它将返回一个简化的URL http ://tinyurl.com/4e9iAk. 要求:设计一个 TinyURL 的加密 encode 和解密 decode 的方法。 你的加密和解密算法如何设计和运作是没有限制的,你只需要保证一个URL可以被加密成一个TinyURL,并且这个TinyURL可以用解密方法恢复成原本的URL。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/encode-and-decode-tinyurl 2.

    56220发布于 2021-02-20
  • 来自专栏站长的编程笔记

    Python - 使用 Tinyurl API 的 URL 缩短器

    为了解决手头的问题,创建了诸如TinyURL之类的网址缩短平台来管理职责。Python 提供了一种方便的方法来连接这些选项。 语法 import requests url = 'http://tinyurl.com/api-create.php? 名为“url”的变量保存TinyURL应用程序编程接口的基本链接。这个“original_url”变量存储我们需要减少长度的网址。 算法 步骤 1:导入请求模块 步骤 2:生成为 TinyURL API 端点设计的主 URL 步骤 3:设置需要缩写的扩展 URL 第 4 步:向 TinyURL 服务发起 HTTP 请求,包括冗长的 通过利用Python编程语言和TinyURL的API,生成更短的网址变得比以往任何时候都容易。通过遵循本文中给出的演示,任何新手程序员都可以使用 TinyURL API 生成网址缩短器。

    1.2K30编辑于 2023-08-11
  • 来自专栏程序IT圈

    ​LeetCode刷题实战535:TinyURL 的加密与解密

    今天和大家聊的问题叫做 TinyURL 的加密与解密,我们先来看题面: https://leetcode-cn.com/problems/encode-and-decode-tinyurl/ TinyURL 是一种URL简化服务, 比如:当你输入一个URL https://leetcode.com/problems/design-tinyurl 时,它将返回一个简化的URL http://tinyurl.com 要求:设计一个 TinyURL 的加密 encode 和解密 decode 的方法。 你的加密和解密算法如何设计和运作是没有限制的,你只需要保证一个URL可以被加密成一个TinyURL,并且这个TinyURL可以用解密方法恢复成原本的URL。 public String encode(String longUrl) { map.put(index, longUrl); return "http://tinyurl.com

    39020编辑于 2022-03-03
  • 来自专栏CodeTime

    短链接的生成方式

    短链接 短链接是一种 URL 简化服务, 比如:当你输入一个 URL https://www.xdull.com 时,它将返回一个简化的URL http://tinyurl.com/weuZn ,其中http ://tinyurl.com/是提供服务的域名,后面的weuZn为简化后的URL的key值,通过这个key能还原成原来的真正的URL。 本文旨在介绍短链接的实现方式,并非在 http://tinyurl.com/ 中存在真实的短链接地址。 12 print(codec.encode("https://www.xdull.cn/tinyurl.html")) # http://tinyurl.com/opaqEprint(codec.encode ("https://www.xdull.cn/Tinyurl.html")) # http://tinyurl.com/fxMk9 如果可以预测要加密的URL数量很多,可适当增大质数m,以使哈希值的范围变得更大

    3.5K20编辑于 2023-03-06
  • 来自专栏机器学习从入门到成神

    2015百度校招笔试真题以及解析(二)

    ---- 2、微博中的url往往很长,发送前要转化为tinyurl 1、url如何转为tinyurl编码 ? 2、如果用户输入一个已经转换过的URL,如何快速定位到已经生成了的tinyurl? 3、如果数据为10亿条,需要10个tinyurl服务器,怎么设计? 比如我们tinyurl长度限制在5个字符,那么可以标示的url数量为34^1+34^2+34^3+34^4+34^5 这是一个非常惊人的数字。 2、数据库中自增ID都是建立索引的, 一个请求的tinyurl我们可以很快的将其还原为唯一ID, 然后直接查询数据库即可以获得原始url, 当然我们在这个过程中可以使用redis, leveldb等kv 2、Decode(tinyurl[:5])/ 916,132,84得到服务器编号,Decode( tinyurl[:5] )是hash值,Decode(tinyurl[5:])是开散列下标。

    77320发布于 2018-09-14
  • 来自专栏肖洒的博客

    叮!你的校招提醒微信机器人已上线!

    -校园交流﹝详细信息﹞: http://tinyurl.com/y7vmoaqr 阿里-菜鸟2018年网络测试开发工程师部门直招﹝详细信息﹞: http://tinyurl.com/yc9xe4eu ( ﹝详细信息﹞: http://tinyurl.com/ya9lxcvw 拼多多技术校招内推﹝详细信息﹞: http://tinyurl.com/ya2plpp7 百度招实习生﹝详细信息﹞: http:/ /tinyurl.com/y9bpe4z2 【散金币】西安闻泰电子科技有限公司人力资源2018校园招聘﹝详细信息﹞: http://tinyurl.com/ybgurcyz 拼多多2019届 校招开始啦 ﹝详细信息﹞: http://tinyurl.com/y94ypr6b 乐馨托管招作业辅导老师一名﹝详细信息﹞: http://tinyurl.com/yc67fjvp 【找家教】给高一的两个孩子找家教 ,报酬丰厚﹝详细信息﹞: http://tinyurl.com/y9c6zwkz 【金币】【招兼职老师】短期老师﹝详细信息﹞: http://tinyurl.com/ybo7araq

    1.8K30发布于 2018-08-07
  • 来自专栏大飞的部落阁

    pyshorteners短链生成神器

    pyshorteners 一个例子入门 from pyshorteners import Shortener # 实例化短链接引擎 short_engine = Shortener() # 使用tinyurl 缩短 res = short_engine.tinyurl.short('https://phygerr.github.io/httpx-%E4%BC%98%E7%A7%80%E7%9A%84http% 短链列表 对于 tinyurl 默认提供缩短功能,但是部分短链接比如 po.st 这种断链是需要注册后使用 APIkey 才能使用调用的。 : 断链 是否需要Key Adf.ly True Bit.ly True Cutt.ly True Git.io True Po.st True Short.cm True Tiny.cc True TinyURL.com phygerr.github.io/httpx-%E4%BC%98%E7%A7%80%E7%9A%84http%E5%AE%A2%E6%88%B7%E7%AB%AF/' # 缩短 res1 = short_engine.tinyurl.short

    2.2K10编辑于 2022-06-17
  • 来自专栏小狼的世界

    Leetcode刷题记录:编码并解码短网址

    self.longurldict[longUrl] = url_code self.urldict[url_code] = longUrl return "http://tinyurl.com /" + url_code def decode(self, shortUrl): domain = "http://tinyurl.com/" shortUrl self.urldict[shortUrl] else: return false url = "https://leetcode.com/problems/design-tinyurl

    60510发布于 2018-07-24
  • 来自专栏JavaEdge

    短链系统设计-用户自定义短链

    public class TinyUrl2 { private HashMap<String,String> s2l = new HashMap<String,String>(); private String> l2s = new HashMap<String,String>(); private int cnt = 0; private final StringBuffer tinyUrl i < 6; i++, j /= 62) res.append(charset.charAt(j % 62)); cnt++; return tinyUrl tiny.url/ */ public String createCustom(String long_url, String key) { String short_url = tinyUrl

    3K20编辑于 2022-09-14
  • 来自专栏Spring相关

    短网址生成相关

    CloseableHttpResponse response = httpClient.execute(post); // 得到调用百度API后成功返回的json字符串 // tinyurl Map<String, String> map = JacksonTemplate.toMap(jsonStr, String.class); return map.get("tinyurl * * 测试 * @param args */ public static void main(String []args){ //String tinyurl

    3K20发布于 2020-11-11
  • 来自专栏流川疯编写程序的艺术

    leetcode 新题型----SQL,shell,system design

    Design TinyURL — system design https://segmentfault.com/a/1190000006140476 Note: For the coding companion problem, please see: Encode and Decode TinyURL. How would you design a URL shortening service that is similar to TinyURL? /design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. /problems/design-tinyurl“.

    1.7K40发布于 2019-01-18
  • 来自专栏其它

    【转】系统设计-第08章:短网址设计

    在这一章中,我们将解决一个有趣而经典的系统设计面试问题:设计一个像tinyurl一样的URL缩短服务。第1步:了解问题并确定设计范围系统设计的面试问题是故意留有余地的。 你的服务创建了一个长度较短的别名:https://tinyurl.com/y7keocwj。如果你单击较短的别名URL,它会将你重定向到原始 URL。候选人:流量是多少?面试官:每天产生1亿个URL。 该API看起来像这样:GET api/v1/shortUrl返回用于HTTP重定向的 longURLURL 重定向图8-1显示了当你在浏览器上输入一个tinyurl时会发生什么。 缩短网址让我们假设短的URL看起来像这样:www.tinyurl.com/{hashValue}。 因此,短网址是:https://tinyurl.com/2TX两种方法的比较下表显示了两种方法的差异。

    50810编辑于 2024-10-29
  • 来自专栏除除的专栏

    构建高效短链接: 原理、SQL 结构与示例代码

    附录: 代码参考 (Node.js)SQL结构 (ORM) - Sequelize:const TinyUrl = sqlIns.define('TinyUrl', {  tiny_id: { // 自增

    20910编辑于 2025-12-26
  • 来自专栏JavaEdge

    短链系统设计-存储设计

    database.create(shortURL=shortURL, longURL=url); return shortURL; } } } public class TinyUrl { public TinyUrl() { long2Short = new HashMap<String, String>(); short2Long 位 = 62^5=0.9B= 9亿 6 位 = 62^6=57B= 570亿 7 位 = 62^7=3.5T= 35000亿 优点:效率高 缺点:强依赖于全局的自增 id public class TinyUrl

    87330编辑于 2022-09-14
  • 来自专栏ByteByteGo学习笔记

    ByteByteGo学习笔记:URL短链服务设计

    param1=value1¶m2=value2,系统应返回 https://tinyurl.com/shortCode 这样的短链接。 URL 重定向机制当用户在浏览器中输入短URL(例如 https://tinyurl.com/y7keocwj)并访问时,浏览器会向URL短链服务发起一个GET请求。 对于 tinyurl.com 这样的URL短链服务,301 重定向通常是更合适的选择。因为其主要目标是提供高效的URL缩短和重定向服务,减少服务器负载,提升用户访问速度。 (展示了用户访问短URL tinyurl.com 时的重定向流程:浏览器发送请求到服务器,服务器查找短URL对应的长URL,并使用301重定向返回给浏览器。)3. 构建短URL: 将域名 (例如 https://tinyurl.com/) 与 hashValue 拼接,生成完整的短URL。

    87200编辑于 2025-02-13
  • 来自专栏Python七号

    分享6个实用的Python自动化脚本

    urlencode from urllib.request import urlopen import sys def make_tiny(url): request_url = ('http://tinyurl.com contextlib.closing(urlopen(request_url)) as response: return response.read().decode('utf-8') def main(): for tinyurl in map(make_tiny, sys.argv[1:]): print(tinyurl) if __name__ == '__main__': main() 这个脚本非常实用,比如说有不是内容平台是屏蔽公众号文章的

    2.3K20发布于 2021-12-02
领券