535. Encode and Decode TinyURL
https://leetcode.com/problems/encode-and-decode-tinyurl/description/
- Solution1: Use increasing numbers to mark tiny urls; actual urls are saved in a indexed list. (If want letters, can transfer the number into 62-based)
- Alternative: Genrate random 6-places string as tiny url. Two dictionaries to allow mapping in two ways and no duplicate.
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 as http://tinyurl.com/4e9iAk
.
Design the encode
and decode
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.
Soulution:
1 | ### s1 ### |
1 | ### s2 ### |