a c++ cheat...


  • 0
    W
    class Solution {
        unordered_map<string,string> decoder;
    public:
        Solution() {
            srand(time(NULL));
        }
        string encode(string longUrl) {
            auto r = rand() % 10000;
            auto h = hash<string>{}(longUrl);
            stringstream ss;
            ss << "http://" << h << r;
            cout << ss.str() << endl;
            decoder[ss.str()]=longUrl;
            return ss.str();
        }
        string decode(string shortUrl) {
            return decoder[shortUrl];
        }
    };
    

Log in to reply
 

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