535.TinyURL的加密和解密
-
链接
leetcode
-
solution:
中等难度,总结来说就是看好题目意思就行,有个标志位能够用来区分长长长,mp<string,string>可以解决查找的麻烦
-
code
class Solution {
public:
map<string,string> mp;
int key=0;
// Encodes a URL to a shortened URL.
string encode(string longUrl) {
string str="tinyurl"+to_string(key);
mp[str]=longUrl;
key++;
return str;
}
// Decodes a shortened URL to its original URL.
string decode(string shortUrl) {
return mp[shortUrl];
}
};
//第二次超双百喔!!
// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));