当前位置:网站首页>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));
}
}
边栏推荐
- [concurrent programming] atomic operation CAS
- 【Rust 笔记】09-特型与泛型
- Life cycle of Servlet
- Find the combination number acwing 885 Find the combination number I
- [concurrent programming] collaboration between threads
- Es8 async and await learning notes
- LinkedList set
- Concurrent programming (III) detailed explanation of synchronized keyword
- Common DOS commands
- Analysis of Alibaba canal principle
猜你喜欢

Drawing maze EasyX library with recursive backtracking method

Complex character + number pyramid

Redux - learning notes

请求参数的发送和接收

First Servlet

MySQL three logs
![[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q](/img/76/6561a78b7f883a0e75a53e037153c3.jpg)
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q

高斯消元 AcWing 883. 高斯消元解线性方程组

Life cycle of Servlet

Too many open files solution
随机推荐
Markdown learning
<, < <,>, > > Introduction in shell
UE4 source code reading_ Mobile synchronization
[set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
Debug debugging - Visual Studio 2022
[RPC] RPC remote procedure call
记忆化搜索 AcWing 901. 滑雪
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
Tree DP acwing 285 A dance without a boss
【Rust 笔记】07-结构体
Gif remove blank frame frame number adjustment
Get the link behind? Parameter value after question mark
Unity editor expansion - draw lines
Format - C language project sub file
高斯消元 AcWing 883. 高斯消元解线性方程组
Unity Editor Extension - Outline
分配异常的servlet
How does unity fixedupdate call at a fixed frame rate
[concurrent programming] concurrent tool class of thread
On the setting of global variable position in C language