当前位置:网站首页>leetcode:535. TinyURL 的加密与解密【url和id的映射,id自增】
leetcode:535. TinyURL 的加密与解密【url和id的映射,id自增】
2022-06-29 15:37:00 【白速龙王的回眸】

分析
简单url和id的映射
ac code
class Codec:
def __init__(self):
self.id = 0
self.db = {
}
def encode(self, longUrl: str) -> str:
"""Encodes a URL to a shortened URL. """
self.id += 1
self.db[self.id] = longUrl
return 'http://tinyurl.com/' + str(self.id)
def decode(self, shortUrl: str) -> str:
"""Decodes a shortened URL to its original URL. """
# rfind最后一个
idx = shortUrl.rfind('/')
id = int(shortUrl[idx + 1:])
return self.db[id]
# Your Codec object will be instantiated and called as such:
# codec = Codec()
# codec.decode(codec.encode(url))
总结
url id 映射
边栏推荐
- postgresql源码学习(24)—— 事务日志⑤-日志写入WAL Buffer
- 11.应用层数据传输格式/端口号-bite
- Digital tracking analysis of insurance services in the first quarter of 2022
- 14.IP协议-bite
- Symfony framework security component firewall configuration
- 架构实战营模块五作业
- Autodesk Revit 2023软件安装包下载及安装教程
- Introduction to radar related contents
- When easygbs calls the interface for obtaining real-time snapshots, how to solve the problem of white squares?
- 为Golang项目编写Makefile
猜你喜欢
随机推荐
R语言plotly可视化:plotly可视化多个数据集归一化直方图(historgram)、设置不同的直方图使用不同的分箱大小(bin size)、在直方图的底部边缘添加边缘轴须图rug
"Game engine shallow in shallow out" 98 Substancepainer plug-in development
Paging SQL (rownum, row_number, deny_rank, rank)
Why MySQL chooses b+ tree to store indexes
关于 国产麒麟系统运行Qt,在命令行可以运行而双击无法运行(无反应) 的解决方法
2022-06-29日报: 李飞飞划重点的「具身智能」,走到哪一步了?
微信公共号开发,发送消息回复文本
京东联盟API - 万能转链接口 - 京品库接口 - 接口定制
LeetCode-234-回文链表
taro3.*中使用 dva 入门级别的哦
面试官:说一下MySQL事务隔离级别?
Swoole TCP distributed implementation
Taro 小程序开启wxml代码压缩
PWM to 0-5v/0-10v/1-5v linear signal transmitter
Several imaging modes of polarimetric SAR
有望显著提高集成光子电路的计算性能,清华团队提出了一种衍射图神经网络框架
swift JSONSerialization
Introduction to radar related contents
wallys/m.2/Adapter card(one pcie1x to 4 x Mini PCIE)
Neural network for remote sensing image processing








