Javascript solution


  • 3
    D
    let urls = {};
    
    var encode = function(longUrl) {
        let uniqueKey = Date.now().toString(36);
        urls[uniqueKey] = longUrl;
        return "http://tinyurl.com/" + uniqueKey;
    };
    
    var decode = function(shortUrl) {
        return urls[shortUrl.split("com/")[1]];
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.