535. Encode and Decode TinyURL

Posted The Tech Road

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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));

 

以上是关于535. Encode and Decode TinyURL的主要内容,如果未能解决你的问题,请参考以下文章

535. Encode and Decode TinyURL

Leetcode 535: Encode and Decode TinyURL

LeetCode 解题思路:535.Encode and Decode TinyURL

535. Encode and Decode TinyURL

leetcode535 - Encode and Decode TinyURL - medium

535. Encode and Decode TinyURL - LeetCode