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 的加密与解密
最新推荐文章于 2022-06-30 00:06:03 发布