详见: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

535 Encode and Decode TinyURL 编码和解码精简URL地址的更多相关文章

  1. [LeetCode] Encode and Decode TinyURL 编码和解码精简URL地址

    Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...

  2. [LeetCode] 535. Encode and Decode TinyURL 编码和解码短网址

    Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...

  3. 535. Encode and Decode TinyURL - LeetCode

    Question 535. Encode and Decode TinyURL Solution 题目大意:实现长链接加密成短链接,短链接解密成长链接 思路:加密成短链接+key,将长链接按key保存 ...

  4. LC 535. Encode and Decode TinyURL

    Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...

  5. 【LeetCode】535. Encode and Decode TinyURL 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 方法一:数组 方法二:字典 日期 题目地址:https://l ...

  6. 【Leetcode】535. Encode and Decode TinyURL

    Question: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/pro ...

  7. 535. Encode and Decode TinyURL

    ▶ 要求给出一种对 URL 网址进行压缩和解压的算法,例如 https://leetcode.com/problems/design-tinyurl ←→ http://tinyurl.com/4e9 ...

  8. 535. Encode and Decode TinyURL 长短URL

    [抄题]: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problem ...

  9. 535. Encode and Decode TinyURL(rand and srand)

    Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...

随机推荐

  1. Appium基础——需要知道的

      Appium使用平台厂商提供的自动化框架: 1.ios 苹果的UIAutomation 2.android google的UIAutomator Appium底层使用厂商提供的自动化框架,就不需要 ...

  2. valid No such filter: 'drawtext'"

    libfreetype is missing. You'll have to rebuild FFmpeg with this library or disable overlays. --enabl ...

  3. jquery之extend

    jquery的extend方法的用法1. [代码][JavaScript]代码     01<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01// ...

  4. 基于logstash+elasticsearch+kibana的日志收集分析方案(Windows)

    一 方案背景     通常,日志被分散的储存不同的设备上.如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志.这样是不是感觉很繁琐和效率低下.开源实时日志分析ELK平台能够完美的 ...

  5. Struts2 拦截器配置及使用

    在我的项目中有个需求,实现记录用户操作的系统日志,基于这个功能我首先想到的是Struts 的拦截器.配置一个全部Action都会拦截的拦截,写一个公用的服务.每当用户发送请求到Action 就记录相应 ...

  6. 51nod最长递增路径:(还不错的图)

    一个无向图,可能有自环,有重边,每条边有一个边权.你可以从任何点出发,任何点结束,可以经过同一个点任意次.但是不能经过同一条边2次,并且你走过的路必须满足所有边的权值严格单调递增,求最长能经过多少条边 ...

  7. codevs 1155今明的预算方案(复习有依赖性的背包问题)

    1155 金明的预算方案 [题目大意]买附件必须买主件. 在一定钱数内 求总价值最大. [题解]有依赖性的背包问题. [code] #include<iostream> #include& ...

  8. bzoj1598

    K短路 和超级钢琴之类的差不多 先反图跑最短路,从原点向外拓展,每个点最多拓展k次,否则不可能是k短路 #include<bits/stdc++.h> using namespace st ...

  9. .net使用DotNetCharting控件生成报表统计图总结

    最近在做项目时要对数据进行统计分析,所以必须生成一些报表统计图(如柱形图.饼图.曲线图等),网上强烈推荐了使用DotNetCharting控件来实现,于是自己对DotNetCharting控件进行了简 ...

  10. Python深入浅出property特性属性

    导语 在Java中,通常在类中定义的成员变量为私有变量,在类的实例中不能直接通过对象.属性直接操作,而是要通过getter和setter来操作私有变量. 而在Python中,因为有property这个 ...