Short C++


  • -1

    C++ version of this thread.

    class Solution {
    public:
        // Encodes a URL to a shortened URL.
        string encode(string longUrl) {
            v.push_back(longUrl);
            return to_string(v.size() - 1);
        }
    
        // Decodes a shortened URL to its original URL.
        string decode(string shortUrl) {
            return v[stoi(shortUrl)];
        }
        
    private:
        vector<string>v;
    };
    

Log in to reply
 

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