class Solution {
public:
map<string,string>m;
// Encodes a URL to a shortened URL.
string encode(string longUrl) {
string s="http://tinyurl"+to_string(rand()%1000);
m[s]=longUrl;
return s;//s指的是加密后的网址
}
// Decodes a shortened URL to its original URL.
string decode(string shortUrl) {
return m[shortUrl];
}
};
// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));
LeetCode:535. TinyURL 的加密与解密
最新推荐文章于 2025-01-10 15:00:00 发布
本文介绍了一种使用随机数生成短链接的算法,并通过map数据结构实现短链接与原始链接之间的映射,便于后续的短链接解码。该算法能够有效地将长链接转化为易于分享的短链接形式。
188

被折叠的 条评论
为什么被折叠?



