当前位置:网站首页>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));
}
}
边栏推荐
- PHP uses foreach to get a value in a two-dimensional associative array (with instances)
- Sending and receiving of request parameters
- Annotations simplify configuration and loading at startup
- TP5 order multi condition sort
- LeetCode 508. 出现次数最多的子树元素和
- Introduction to the usage of getopts in shell
- Redux - learning notes
- LeetCode 532. K-diff number pairs in array
- ES6 promise learning notes
- LeetCode 715. Range 模块
猜你喜欢

MySQL three logs

Slice and index of array with data type

Notes and bugs generated during the use of h:i:s and y-m-d

干货!零售业智能化管理会遇到哪些问题?看懂这篇文章就够了

Discussion on enterprise informatization construction

Mortgage Calculator

too many open files解决方案

数位统计DP AcWing 338. 计数问题

Try to reprint an article about CSDN reprint

LeetCode 30. 串联所有单词的子串
随机推荐
LeetCode 30. 串联所有单词的子串
Vscode connect to remote server
PHP uses foreach to get a value in a two-dimensional associative array (with instances)
How to delete CSDN after sending a wrong blog? How to operate quickly
记忆化搜索 AcWing 901. 滑雪
Binary tree sorting (C language, int type)
cres
22-05-26 Xi'an interview question (01) preparation
AcWing 785. Quick sort (template)
Redux - learning notes
传统办公模式的“助推器”,搭建OA办公系统,原来就这么简单!
Concurrent programming (III) detailed explanation of synchronized keyword
求组合数 AcWing 886. 求组合数 II
AcWing 787. Merge sort (template)
Analysis of Alibaba canal principle
精彩回顾|I/O Extended 2022 活动干货分享
Find the combination number acwing 885 Find the combination number I
ES6 promise learning notes
Tree DP acwing 285 A dance without a boss
Monotonic stack -84 The largest rectangle in the histogram