LeetCode 535. Encode and Decode TinyURL
题目描述:
TinyURL is a URL shortening service where you enter a URL such as
https://leetcode.com/problems/design-tinyurl
and it returns a short URL such ashttp://tinyurl.com/4e9iAk
.Design the
encode
anddecode
methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.Note: Do not use class member/global/static variables to store states. Your encode and decode algorithms should be stateless.
短链接的维护,但不限制内部如何生成短链接。就是Hash表的问题,我直接使用的unordered_map
容器所提供的Hash函数对原链接进行处理,得到一个数值,然后将该数值转换为62进制字符串(10个数字+大小写字母各26个),该字符串作为短链接的后缀部分。
1 | class Solution { |