using System.Collections.Generic;
public static void Main()
string tiny1 = Codec.encode("https://leetcode.com/problems/design-tinyurl-1");
string tiny2 = Codec.encode("https://leetcode.com/problems/design-tinyurl-2");
Console.WriteLine(Codec.decode(tiny1) + " - " + tiny1);
Console.WriteLine(Codec.decode(tiny2) + " - " + tiny2);
public static class Codec {
static char[] map = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'0','1','2','3','4','5','6','7','8','9'};
static Dictionary<string,string> memStore = new Dictionary<string,string>();
public static string encode(string longUrl) {
string shortUrl = string.Empty;
shortUrl += map[val % 62];
shortUrl = Reverse(shortUrl);
memStore.Add(shortUrl,longUrl);
public static string decode(string shortUrl) {
return memStore[shortUrl];
public static string Reverse( string s )
char[] charArray = s.ToCharArray();
Array.Reverse( charArray );
return new string( charArray );