535. Encode and Decode TinyURL

class Solution {
public:
    long max_id = 0;
    unordered_map<long,string> id_long;
    
    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
        id_long[max_id++] = longUrl;
        return to_string(max_id - 1);
    }

    // Decodes a shortened URL to its original URL.
    string decode(string shortUrl) {
        long id = stol(shortUrl);
        return id_long[id];
    }
};

// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));

猜你喜欢

转载自www.cnblogs.com/JTechRoad/p/9108544.html
今日推荐