当前位置:网站首页>leetcode:535. Encryption and decryption of tinyurl [mapping of URL and ID, ID self increment]
leetcode:535. Encryption and decryption of tinyurl [mapping of URL and ID, ID self increment]
2022-06-29 16:04:00 【Review of the white speed Dragon King】

analysis
Simple url and id Mapping
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 the last one
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))
summary
url id mapping
边栏推荐
- 如何使用SMS向客户传递服务信息?指南在这里!
- Autodesk Revit 2023软件安装包下载及安装教程
- Business Intelligence BI and business management decision-making thinking No. 3: business quality analysis
- 架构实战营模块五作业
- Google 软件版本经历周期
- mysql数据库基础:DDL数据定义语言
- Kotlin annotation Statement and use
- MySQL XA distributed transaction
- Summary of recent work
- 如何在你的 wordpress 网站中添加搜索框
猜你喜欢

Stlink troubleshooting
[data analysis] five common questions about learning SQL?

LeetCode-64-最小路径和

Leetcode-470- implement rand10() with rand7()

CVPR 2022 | greatly reduce the manual annotation required for zero sample learning. Mapuosuo and Beiyou proposed category semantic embedding rich in visual information

《网络是怎么样连接的》读书笔记 - 服务器端的局域网中(四)

C # learning 1: value type and reference type

C#学习一:值类型与引用类型

Huawei cloud AOM version 2.0 release

What are the advantages of intelligent chat robots? Senior independent station sellers tell you!
随机推荐
mysql报错:Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column
【Rust日报】 Rust 2021-稳定性
虚拟主机、WordPress 主机和云主机之间的区别
Three development trends of enterprise application viewed from the third technological revolution
等保测评结论为差,是不是表示等保工作白做了?
How to create a login page in WordPress
BS-GX-017基于SSM实现的在线考试管理系统
Andorid Jetpack Hilt
Kotlin annotation declaration and use
火山引擎入选国内首个《边缘计算产业全景图》
微信公共号开发,发送消息回复文本
Andorid Jetpack Hilt
如何在你的 wordpress 网站中添加搜索框
kotlin 注解聲明與使用
I want to know where I can open an account in Nanning? In addition, is it safe to open a mobile account?
LeetCode-234-回文链表
When easygbs calls the interface for obtaining real-time snapshots, how to solve the problem of white squares?
天谋科技 Timecho 完成近亿元人民币天使轮融资,围绕 Apache IoTDB 打造工业物联网原生时序数据库
事件相关电位ERP的皮层溯源分析
【crossbeam系列】5 crossbeam-util和crossbeam-queue:一些实用的小东西