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
535 Encode and Decode TinyURL 编码和解码精简URL地址的更多相关文章
- [LeetCode] Encode and Decode TinyURL 编码和解码精简URL地址
Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...
- [LeetCode] 535. Encode and Decode TinyURL 编码和解码短网址
Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...
- 535. Encode and Decode TinyURL - LeetCode
Question 535. Encode and Decode TinyURL Solution 题目大意:实现长链接加密成短链接,短链接解密成长链接 思路:加密成短链接+key,将长链接按key保存 ...
- LC 535. Encode and Decode TinyURL
Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...
- 【LeetCode】535. Encode and Decode TinyURL 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 方法一:数组 方法二:字典 日期 题目地址:https://l ...
- 【Leetcode】535. Encode and Decode TinyURL
Question: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/pro ...
- 535. Encode and Decode TinyURL
▶ 要求给出一种对 URL 网址进行压缩和解压的算法,例如 https://leetcode.com/problems/design-tinyurl ←→ http://tinyurl.com/4e9 ...
- 535. Encode and Decode TinyURL 长短URL
[抄题]: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problem ...
- 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 ...
随机推荐
- RobotFramework教程使用笔记——Selenium2Library库
selenium之前已经学习介绍过了,它是一个支持多语言.多平台.多浏览器的web自动化测试框架,在robotframework中也可以导入selenium库来进行web自动化测试.它使用seleni ...
- codeforces 669A A. Little Artem and Presents(水题)
题目链接: A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes ...
- 如何用Adb连接Android手机 & unable to connect to 192.168.1.100:5555的原因和解决方法
利用adb来连接手机, 有两种方式: 1, wifi 2, usb. 1. 通过wifi, 利用adb来连接手机. 在pc的cmd中输入命令: adb connect 192.168.1.100 其中 ...
- docker 学习(六) export/import/load/save images
export/import 是一对命令: load/save是一对命令 一: export / import使用 1: 查看镜像: docker ps -a 2:导出镜像:docker ex ...
- win7 第一次装 mysql-5.7.16-winx64 ,不知道root 密码,该如何处理?
转载请注明出处:http://blog.csdn.net/qq_26093511/article/details/52851811 ERROR 1045 (28000): Access denied ...
- java集合框架之Collection
参考http://how2j.cn/k/collection/collection-collection/366.html Collection是 Set List Queue和 Deque的接口Qu ...
- java泛型基础、子类泛型不能转换成父类泛型--未完待续
参考http://how2j.cn/k/generic/generic-generic/373.html 1.使用泛型的好处:泛型的用法是在容器后面添加<Type>Type可以是类,抽象类 ...
- Flutter实战视频-移动电商-10.首页_FlutterSwiper轮播效果制作
10.首页_FlutterSwiper轮播效果制作 博客地址: https://jspang.com/post/FlutterShop.html#toc-5c2 flutter_swiper http ...
- Flutter实战视频-移动电商-17.首页_楼层组件的编写技巧
17.首页_楼层组件的编写技巧 博客地址: https://jspang.com/post/FlutterShop.html#toc-b50 楼层的效果: 标题 stlessW快速生成: 接收一个St ...
- PHP实用小程序(三)
<HTML> <HEAD> <TITLE>给数组增加元素</TITLE> </HEAD> <? $Cities[] = "& ...