当前位置:网站首页>[daily training] 535 Encryption and decryption of tinyurl
[daily training] 535 Encryption and decryption of tinyurl
2022-06-29 18:38:00 【Puppet__】
subject
TinyURL It's a kind of URL Simplify services , such as : When you enter a URL https://leetcode.com/problems/design-tinyurl when , It will return a simplified URL http://tinyurl.com/4e9iAk . Please design a class to encrypt and decrypt TinyURL .
There is no limit to how encryption and decryption algorithms are designed and operated , You just need to guarantee one URL Can be encrypted into a TinyURL , And this TinyURL It can be restored to the original by decryption URL .
Realization Solution class :
Solution() initialization TinyURL System object .
String encode(String longUrl) return longUrl Corresponding TinyURL .
String decode(String shortUrl) return shortUrl The original URL . The subject data guarantees a given shortUrl Is encrypted by the same system object .
Example :
Input :url = “https://leetcode.com/problems/design-tinyurl”
Output :“https://leetcode.com/problems/design-tinyurl”
explain :
Solution obj = new Solution();
string tiny = obj.encode(url); // Returns the result of encryption TinyURL .
string ans = obj.decode(tiny); // Returns the original after decryption URL .
Tips :
1 <= url.length <= 104
Topic data assurance url Is an effective URL
Code
package dayLeetCode;
import java.util.HashMap;
import java.util.Map;
public class dayleetcode535 {
// Add a unique ID
Map<Integer, String> map = new HashMap<>();
int id;
// Encodes a URL to a shortened URL.
public String encode(String longUrl) {
id++;
map.put(id, longUrl);
return "http://tinyurl.com/" + id;
}
// Decodes a shortened URL to its original URL.
public String decode(String shortUrl) {
// obtain id It's the number one character
int k = shortUrl.lastIndexOf('/') + 1;
// Before removal k Characters
int id = Integer.parseInt(shortUrl.substring(k));
return map.get(id);
}
}
边栏推荐
- JDBC knowledge
- 3H proficient in opencv (V) - perspective transformation
- jdbc_ Related codes
- 记录服务器被入侵病毒:ssh密码被更改登录失败、恶意程序跑满了cpu、jar包启动失败自动kill、一直弹出You have new mail in /var/spool/mail/root
- svg画圆路径动画
- VMware installation esxi
- 什么是多范式编程语言,其中的“多范式”是什么意思?
- Source code installation mavros
- Mysql database daily backup and scheduled cleanup script
- 如何在树莓派上使用OAK相机?
猜你喜欢

Failed to allocate graph: myriad device is not opened

js文本粒子动态背景

jdbc_相关代码

centos 7.5安装mysql 8.0.27----yum

《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26

The 8th "Internet +" competition - cloud native track invites you to challenge

报错Failed to allocate graph: MYRIAD device is not opened.

Cannot retrieve repository metadata processing records

About microservices

My first experience of remote office | community essay solicitation
随机推荐
Know that Chuangyu has helped the energy industry in asset management and was selected into the 2021 IOT demonstration project of the Ministry of industry and information technology
Adobe Premiere Basics - common video effects (corner positioning, mosaic, blur, sharpen, handwriting tools, effect control hierarchy) (16)
Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)
6.29 simulation summary
Weibo comments on high-performance and high availability architecture design (module 5 of architecture practice camp)
行程卡“摘星”热搜第一!刺激旅游产品搜索量齐上涨
优雅书写Controller(参数验证+统一异常处理)
svg画圆路径动画
【TcaplusDB知识库】TcaplusDB单据受理-创建游戏区介绍
Adobe Premiere基礎-聲音調整(音量矯正,降噪,電話音,音高換擋器,參數均衡器)(十八)
How to use idea?
Markdown knowledge comes gently
JDBC Codes connexes
The 8th "Internet +" competition - cloud native track invites you to challenge
3H proficient in opencv (VII) - color detection
Anaconda installs and configures jupyter notebook remote
【TcaplusDB知识库】TcaplusDB运维单据介绍
data-*属性用法
Sister Juan takes you to learn database -- 5-day dash day4
Apache Doris 基本使用总结