C# Solution (Encode and Decode TinyURL)

  • 0
    public class Codec {
         List<string> table = new List<string>();
            public string encode(string longUrl) 
                string shortURL = longUrl;
                shortURL = Convert.ToString(table.IndexOf(longUrl));
                return shortURL; 
            public string decode(string shortUrl) 
                int index = Convert.ToInt32(shortUrl);
                string longURL = table[index];
                return longURL; 

Log in to reply

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