TinyURL is a URL shortening service where do I enter a URL such https://leetcode.com/problems/design-tinyurl
as and it returns a short URL such as .
Design the and methods for the TinyURL service. decode
encode
There is no restriction on what your encode/decode algorithm should work. You just need to ensure, that a URL can is encoded to a tiny URL and the tiny URL can is decoded to the original URL.
Encode: Press Longurl into the stack and convert the Longurl suffix to a number added to the tinyurl suffix.
Decode: Find the suffix number of the tinyurl and return the longurl corresponding to the number in the stack.
classSolution { Public: Vector<string>URLs; //encodes a URL to a shortened URL. stringEncodestringLongurl) {Urls.push_back (Longurl); return "http://tinyurl.com/"+ to_string (urls.size ()-1); } //decodes a shortened URL to its original URL. stringDecodestringShorturl) {Auto pos= Shorturl.find_last_of ('/'); intnum = Stoi (SHORTURL.SUBSTR (pos +1)); returnUrls[num]; }};//3ms//Your Solution Object would be instantiated and called as such://solution solution;//solution.decode (Solution.encode (URL));
[Leetcode] Encode and Decode TinyURL