首页 » C++ » LeetCode 535. Encode and Decode TinyURL

LeetCode 535. Encode and Decode TinyURL

原文 http://blog.csdn.net/sinat_36053757/article/details/75213430

2017-07-17 01:20:03阅读(792)

题目:
Note: This is a companion problem to the System Design problem: Design TinyURL.
TinyURL is a URL shortening service where you enter a URL such as https://LeetCode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk.

Design the encode and Decode methods for the TinyURL service. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL.

思路:
这题没啥可说,因为调用solution.decode(solution.encode(url));的关系,就两行代码

代码:

class Solution {
public:
    // Encodes a URL to a shortened URL.
    string encode(string longUrl) {
        return longUrl;
    }
    // Decodes a shortened URL to its original URL.
    string decode(string shortUrl) {
         return shortUrl;
    }
};
// Your Solution object will be instantiated and called as such:
// Solution solution;
// solution.decode(solution.encode(url));

输出结果: 3ms

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹