leetcode 535. Encode and Decode TinyURL
来源:互联网 发布:大数据下的人力资源 编辑:程序博客网 时间:2024/06/08 01:58
这个题目如果自己写一个算法的话确实很难,但是这个是没有什么要求的,因此就简单多了。最简单的就是不做任何处理,直接返回
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; }};
但是这种解法很无聊,因此我用了一种简单映射的方法来实现,设置一个count用来保证不同url的不同id。
class Solution {public: map<string,string> m; int count=0; // Encodes a URL to a shortened URL. string encode(string longUrl) { string shortUrl=to_string(count); m.insert(pair<string,string>(shortUrl,longUrl)); count++; return shortUrl; } // Decodes a shortened URL to its original URL. string decode(string shortUrl) { return m[shortUrl]; }};
阅读全文
0 0
- leetcode题解-535. Encode and Decode TinyURL
- 【LeetCode】535. Encode and Decode TinyURL
- LeetCode:535. Encode and Decode TinyURL
- Leetcode 535. Encode and Decode TinyURL
- leetcode 535. Encode and Decode TinyURL
- Leetcode 535. Encode and Decode TinyURL
- LeetCode 535. Encode and Decode TinyURL
- 【LeetCode】535. Encode and Decode TinyURL
- python--leetcode 535. Encode and Decode TinyURL
- leetcode 535. Encode and Decode TinyURL
- LeetCode-Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- 535. Encode and Decode TinyURL
- Week4Day1
- hdu 1114 Piggy-Bank 完全背包
- 10-15&&10-16NOIP模拟赛总结
- 学习linux!
- 多线程MFC
- leetcode 535. Encode and Decode TinyURL
- MAC快捷键使用大全
- 我们为什么要学习PHP?PHP的应用领域有哪些?
- 【MySql】数据库连接异常:The last packet sent successfully to the server was 0 milliseconds ago
- 路径fuzz的一种想法(脚本试验扫了一晚上,扫出某大厂商两个漏洞)
- ios-正则表达式基础
- bzoj1307玩具/1318[Spoj744] Longest Permutation
- 10.16(周一)
- 关于 maven 项目打包 乱码问题