当前位置:网站首页>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));
}
}
边栏推荐
- Shell script kills the process according to the port number
- LeetCode 508. The most frequent subtree elements and
- The difference between if -n and -z in shell
- Binary to decimal, decimal to binary
- Escape from heaven and forget what he suffered. In ancient times, it was called the punishment of escape from heaven. Article collection
- Complex character + number pyramid
- First Servlet
- file_ put_ contents
- LeetCode 57. 插入区间
- 使用dlv分析golang进程cpu占用高问题
猜你喜欢
Tree DP acwing 285 A dance without a boss
Markdown learning
Concurrent programming (V) detailed explanation of atomic and unsafe magic classes
Log4j2 vulnerability recurrence and analysis
Basic knowledge of network security
Vscode connect to remote server
LeetCode 241. 为运算表达式设计优先级
LeetCode 57. 插入区间
Phpstudy 80 port occupied W10 system
我们有个共同的名字,XX工
随机推荐
AcWing 788. 逆序对的数量
Solution of 300ms delay of mobile phone
Complex character + number pyramid
[rust notes] 12 closure
低代码起势,这款信息管理系统开发神器,你值得拥有!
Life cycle of Servlet
推荐一个 yyds 的低代码开源项目
Apache startup failed phpstudy Apache startup failed
Gaussian elimination acwing 883 Gauss elimination for solving linear equations
20220630 learning clock in
LeetCode 871. 最低加油次数
In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
Sword finger offer II 029 Sorted circular linked list
Facial expression recognition based on pytorch convolution -- graduation project
Log4j2 vulnerability recurrence and analysis
[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 787. Merge sort (template)
Slice and index of array with data type
Too many open files solution
Concurrent programming (VI) ABA problems and solutions under CAS