Final C++ solution


  • -1
    W

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

    public:
    Solution():m_index(0) {}
    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
    string tiny = indexAsString();
    m_tinyToUrl[tiny] = longUrl;
    m_index++;
    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.