535 Encode and Decode TinyURL 编码和解码精简URL地址

详见:https://leetcode.com/problems/encode-and-decode-tinyurl/description/

C++:

class Solution {
public: // Encodes a URL to a shortened URL.
string encode(string longUrl)
{
url.push_back(longUrl);
return "http://tinyurl.com/" + to_string(url.size() - 1);
} // Decodes a shortened URL to its original URL.
string decode(string shortUrl)
{
auto pos = shortUrl.find_last_of("/");
return url[stoi(shortUrl.substr(pos + 1))];
} private:
vector<string> url;
}; // Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));

参考:http://www.cnblogs.com/grandyang/p/6562209.html

上一篇:[LeetCode] Design Search Autocomplete System 设计搜索自动补全系统


下一篇:RadHat搭建内网YUM源server