题目链接: TinyURL 的加密与解密
题目描述
解体思路
- 我们加密的字符串,我们让第一个元素添加一个asc码位
- 我们解密的字符串。我们让第一个元素减少一个asc码位
代码实现
class Solution {
public:
// Encodes a URL to a shortened URL.
string encode(string longUrl) {
longUrl[0]++;
return longUrl;
}
// Decodes a shortened URL to its original URL.
string decode(string shortUrl) {
shortUrl[0]--;
return shortUrl;
}
};
// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));