Note: This is a companion problem to the System Design problem: Design 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 as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL.

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.

Implement the Solution class:


	Solution() Initializes the object of the system.
	String encode(String longUrl) Returns a tiny URL for the given longUrl.
	String decode(String shortUrl) Returns the original long URL for the given shortUrl. It is guaranteed that the given shortUrl was encoded by the same object.


&nbsp;
Example 1:

Input: url = "https://leetcode.com/problems/design-tinyurl"
Output: "https://leetcode.com/problems/design-tinyurl"

Explanation:
Solution obj = new Solution();
string tiny = obj.encode(url); // returns the encoded tiny url.
string ans = obj.decode(tiny); // returns the original url after deconding it.


&nbsp;
Constraints:


	1 &lt;= url.length &lt;= 104
	url is guranteed to be a valid URL.


class Codec:

    def encode(self, longUrl):
        return longUrl

    def decode(self, shortUrl):
        return shortUrl
public class Codec {

    // Encodes a URL to a shortened URL.
    public String encode(String longUrl) {
        return longUrl;
    }

    // Decodes a shortened URL to its original URL.
    public String decode(String shortUrl) {
        return shortUrl;
    }
}
class Solution {
private:
    unordered_map<string, string> hash;
    string server = "http://tinyurl.com/";
    string all = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";

public:

    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
        srand(time(NULL));
        string add = "";
        int ran = rand() % 10;
        int strsize = all.size();
        while(ran){
            int index = rand() % strsize;
            add += all[index];
            ran--;
        }

        hash[(server+add)] = longUrl;

        return (server + add);
    }

    // Decodes a shortened URL to its original URL.
    string decode(string shortUrl) {
        return hash[shortUrl];
    }
};

// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));
let arr = new Array();
let size = 0;

var encode = function(longUrl) {
    arr.push(longUrl)
    let i = longUrl.indexOf('/',11);
    longUrl.slice(i);
    longUrl += this.size;
    arr.push(longUrl);
    size += 2;
    return longUrl;
};

var decode = function(shortUrl) {
    let i = 0;
    while(arr[i] !== shortUrl && i<size){
        i++;
    }
    return arr[i-1];
};
Encode and Decode TinyURL