当前位置:网站首页>LeetCode 535. TinyURL 的加密与解密
LeetCode 535. TinyURL 的加密与解密
2022-07-03 08:49:00 【Sasakihaise_】
【分析】其实这道题主要就是考察设置两个字符串,如何在两个字符串之间做好映射,那么最简单的一种就是直接用相同字符串。或者可以用自增的ID来进行哈希映射。
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));
}
}
边栏推荐
- 【Rust笔记】05-错误处理
- Deep parsing JVM memory model
- Redis cluster series 4
- Baidu editor ueeditor changes style
- Location of package cache downloaded by unity packagemanager
- Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
- Try to reprint an article about CSDN reprint
- XPath实现XML文档的查询
- [rust notes] 09- special types and generics
- php public private protected
猜你喜欢
UE4 source code reading_ Bone model and animation system_ Animation compression
Try to reprint an article about CSDN reprint
Log4j2 vulnerability recurrence and analysis
Concurrent programming (III) detailed explanation of synchronized keyword
Facial expression recognition based on pytorch convolution -- graduation project
Unity Editor Extension - drag and drop
Tree DP acwing 285 A dance without a boss
How to use Jupiter notebook
Annotations simplify configuration and loading at startup
Find the combination number acwing 886 Find the combination number II
随机推荐
[concurrent programming] explicit lock and AQS
樹形DP AcWing 285. 沒有上司的舞會
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
PHP uses foreach to get a value in a two-dimensional associative array (with instances)
Mortgage Calculator
Common DOS commands
使用dlv分析golang进程cpu占用高问题
Facial expression recognition based on pytorch convolution -- graduation project
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
How does unity fixedupdate call at a fixed frame rate
UE4 source code reading_ Mobile synchronization
Unity notes 1
[concurrent programming] Table hopping and blocking queue
Phpstudy 80 port occupied W10 system
DOM 渲染系统(render mount patch)响应式系统
二进制转十进制,十进制转二进制
Collection interface
[rust notes] 08 enumeration and mode
Redux - learning notes
ES6 promise learning notes