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 ...
随机推荐
- shell动态变量
面对变量中嵌套变量,可以这么做 other_devops_ip="......." options='_ip' tennat_name='other_devops' tennat_ ...
- 【转载】malloc和new
1.malloc与free是C++/C语言的标准库函数,new/delete是C++的运算符.它们都可用于申请动态内存和释放内存2.对于非内部数据类型的对象而言,光用maloc/free无法满足动态对 ...
- RAM的分类
转载自:http://wenku.baidu.com/view/b17d73244b35eefdc8d333ab.html RAM(随机存储器)可以分为SRAM(静态随机存储器)和DRAM(动态随机存 ...
- DBCPTool
dbcp读取配置文件的方式: 1. 导入3个包:commons-dbcp-... .jar(数据源) commons-collections-.....jar(集合) commons-pool... ...
- vue全局配置
Vue.config 是一个对象,包含Vue的全局配置.可以在启动应用之前修改下列的属性: Vue.config.slient=true; 取消Vue所有的日志与警告 默认值false ...
- Docker运行MongoDB及Redis及ssh端口映射远程连接
Docker运行MongoDB及Redis及ssh端口映射远程连接 本节内容简介 在本实验里我们将通过完成 MongoDB 和 Redis 两个容器来学习Dockerfile及Docker的运行机制. ...
- 系统管理常用Linux命令
1.查看系统运行时间.用户数.负载 uptime 11:00:39 up 3 days, 1:08, 1 user, load average: 0.00, 0.01, 0.05 解析:后面的三 ...
- ElasticSearch基础+文档CRUD操作
本篇博客是上一篇的延续,主要用来将年前学习ES的知识点做一个回顾,方便日后进行复习和汇总!因为近期项目中使用ES出现了点小问题,因此在这里做一个详细的汇总! [01]全文检索和Lucene (1)全文 ...
- web前端_Vue框架_设置浏览器上方的标题和图标
在创建Vue项目时一般会用默认的项目标题和图标,如下图所示: 不是很美观也可能不符合项目的需求,所以有时候就需要改变项目在浏览器上方的标签名称或者图标. 找到项目根目录的index.html,如图: ...
- 51nod 1067【简单博弈】
卧槽,第一次自己推推推做出来的... 对于1,那么就是A取完就好 --A 对于2,只能是A拿一个 --B 对于3和4,都是A拿完 --A 对于5,靠向2,A取3,B只能1 --A 对于6,A取一个的话 ...