Final C++ solution

  • -1

    class Solution {
    map<string, string> m_tinyToUrl;
    long m_index;
    string indexAsString() {
    return std::to_string(m_index);

    Solution():m_index(0) {}
    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
    string tiny = indexAsString();
    m_tinyToUrl[tiny] = longUrl;
    return tiny;

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



Log in to reply

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