[抄题]:

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.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

完全不知道用什么数据结构来实现

[一句话思路]:

短URL必须是在当前的arraylist中,自己生成的才可以

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

同一个arraylist中自产自销就可以,不是就不行

[复杂度]:Time complexity: O(n) Space complexity: O(n)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

ArrayList动态添加

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

public class Codec {
List<String> urls = new ArrayList<String>(); // Encodes a URL to a shortened URL.
public String encode(String longUrl) {
urls.add(longUrl);
return String.valueOf(urls.size() - 1);
} // Decodes a shortened URL to its original URL.
public String decode(String shortUrl) {
int index = Integer.valueOf(shortUrl);
return (index <= urls.size()) ? urls.get(index) : "";
}
} // Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.decode(codec.encode(url));

535. Encode and Decode TinyURL 长短URL的更多相关文章

  1. 535. Encode and Decode TinyURL - LeetCode

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

  2. LC 535. Encode and Decode TinyURL

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

  3. 【Leetcode】535. Encode and Decode TinyURL

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

  4. 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 ...

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

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

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

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

  7. 535 Encode and Decode TinyURL 编码和解码精简URL地址

    详见:https://leetcode.com/problems/encode-and-decode-tinyurl/description/ C++: class Solution { public ...

  8. 535. Encode and Decode TinyURL

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

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

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

随机推荐

  1. I.MX6 Android 设备节点权限

    /********************************************************************************** * I.MX6 Android ...

  2. linux 下看所有用户 及所有组

    俺的centos vps上面不知道添加了多少个账户,今天想清理一下,但是以前还未查看过linux用户列表,google了一下,找到方便的放:一般情况下是 cat /etc/passwd 可以查看所有用 ...

  3. SQLmap是一款用来检测与利用SQL漏洞的注入神器。

    sqlmap 重要参考 http://www.kali.org.cn/forum-75-1.html SQLmap是一款用来检测与利用SQL漏洞的注入神器.开源的自动化SQL注入工具,由Python写 ...

  4. sqlalchemy的缓存和刷新

    其实只是第一次查询了数据库,其他的时候都使用的是缓存,所以有时候,因为这个特性会出错,所以需要刷新对象或者使对象过期 参考链接:http://www.cnblogs.com/fengyc/p/5369 ...

  5. 深入浅出K-Means算法

    在数据挖掘中,K-Means算法是一种cluster analysis的算法,其主要是来计算数据聚集的算法,主要通过不断地取离种子点最近均值的算法. 问题 K-Means算法主要解决的问题如下图所示. ...

  6. SQLSERVER 2008 查询数据字段名类型

    SELECT * FROM Master..SysDatabases ORDER BY Name SELECT Name,* FROM Master..SysDatabases where Name= ...

  7. tp5操作mongo

    1.通过composer安装 composer require mongodb/mongodb 2.使用 <?php /** * @author: jim * @date: 2017/11/17 ...

  8. 010. VS2015创建MVC项目

    1. 文件→新建→项目 2.选择空模板→选中MVC 3. 预览(如果是使用aspx, 则可以删除Views中的web.config, 如果使用Razor则不要删除, 否则会报Views/Home/In ...

  9. 0003-程序流程1之app.js

    index.html中引入各种依赖的文件 由ng-app处开始angular Js的管理 angular.module('App', ['']) .run(function($rootScope,.. ...

  10. 实验吧CTF题库-WEB题(部分)

    看起来有点难 提交admin http://ctf5.shiyanbar.com/basic/inject/index.php?admin=admin&pass=admin&actio ...