当前位置:网站首页>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));
}
}
边栏推荐
- Solution of 300ms delay of mobile phone
- C language file reading and writing
- Graphics_ Games101/202 learning notes
- 22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
- 单调栈-42. 接雨水
- DOM 渲染系统(render mount patch)响应式系统
- Message queue for interprocess communication
- First Servlet
- [rust notes] 06 package and module
- Final review of Database Principles
猜你喜欢

Markdown learning

Log4j2 vulnerability recurrence and analysis

Unity editor expansion - draw lines

Final review of Database Principles

Really explain the five data structures of redis

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

Facial expression recognition based on pytorch convolution -- graduation project

Unity interactive water ripple post-treatment

Debug debugging - Visual Studio 2022

记忆化搜索 AcWing 901. 滑雪
随机推荐
Unity editor expansion - the design idea of imgui
JS non Boolean operation - learning notes
求组合数 AcWing 885. 求组合数 I
Too many open files solution
[rust notes] 07 structure
createjs easeljs
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
22-05-26 Xi'an interview question (01) preparation
22-06-27 Xian redis (01) commands for installing five common data types: redis and redis
php public private protected
[rust notes] 13 iterator (Part 1)
Unity Editor Extension - event handling
Development experience and experience
[concurrent programming] concurrent security
Try to reprint an article about CSDN reprint
Message queue for interprocess communication
SQL statement error of common bug caused by Excel cell content that is not paid attention to for a long time
Binary tree sorting (C language, int type)
求组合数 AcWing 886. 求组合数 II
Unity Editor Extension - drag and drop