当前位置:网站首页>LeetCode 535. Encryption and decryption of tinyurl
LeetCode 535. Encryption and decryption of tinyurl
2022-07-03 09:02:00 【Sasakihaise_】
535. TinyURL Encryption and decryption

【 analysis 】 In fact, this question is mainly about setting two strings , How to map between two strings , Then the simplest one is to use the same string directly . Or you can use self increasing ID For hash mapping .
public class Codec {
Map<Integer, String> map = new HashMap();
int cnt = 0;
// Encodes a URL to a shortened URL.
public String encode(String longUrl) {
map.put(cnt++, longUrl);
return Integer.toString(cnt - 1);
}
// Decodes a shortened URL to its original URL.
public String decode(String shortUrl) {
return map.get(Integer.parseInt(shortUrl));
}
}
边栏推荐
- 20220630 learning clock in
- PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
- LeetCode 508. The most frequent subtree elements and
- How to place the parameters of the controller in the view after encountering the input textarea tag in the TP framework
- 树形DP AcWing 285. 没有上司的舞会
- LeetCode 75. 颜色分类
- 20220630学习打卡
- XPath实现XML文档的查询
- 干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了
- 数字化管理中台+低代码,JNPF开启企业数字化转型的新引擎
猜你喜欢

LeetCode 513. 找树左下角的值

Query XML documents with XPath

Divide candy (circular queue)

22-06-28 西安 redis(02) 持久化机制、入门使用、事务控制、主从复制机制

常见渗透测试靶场

Complex character + number pyramid

Tree DP acwing 285 A dance without a boss

Memory search acwing 901 skiing

Find the combination number acwing 885 Find the combination number I

On the setting of global variable position in C language
随机推荐
Parameters of convolutional neural network
PIC16F648A-E/SS PIC16 8位 微控制器,7KB(4Kx14)
Find the combination number acwing 886 Find the combination number II
LeetCode 508. The most frequent subtree elements and
On the setting of global variable position in C language
[concurrent programming] atomic operation CAS
Get the link behind? Parameter value after question mark
Common DOS commands
Final review of Database Principles
Life cycle of Servlet
教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
PHP mnemonic code full text 400 words to extract the first letter of each Chinese character
Wonderful review | i/o extended 2022 activity dry goods sharing
Divide candy (circular queue)
JS non Boolean operation - learning notes
Drawing maze EasyX library with recursive backtracking method
Arbre DP acwing 285. Un bal sans patron.
Find the combination number acwing 885 Find the combination number I
How to use Jupiter notebook
Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection