[抄题]:

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. 前端之JavaScript 补充

    1. BOM window location.href = "https://www.sogo.com" location.reload() // 重新加载当前页 location ...

  2. 剑指offer-第六章面试中的各项能力(圆圈中剩下的最后数字)

    import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util ...

  3. noip济南清北冲刺班DAY2

    题解: 贪心+dp 30% N<=5  5!枚举一下 20%  高度没有的时候,高度花费就不存在了,将ci排序, 从小到大挨个跳.另外,20% 准备跳楼没有花费,那么跳 楼的高度一定是从小到大, ...

  4. 在DIV里面让图片居中

    .content.itemDiv{ display: table-cell;width: 171px;height: 133px;text-align: center; vertical-align: ...

  5. (转)android - anim translate中 fromXDelta、toXDelta、fromYDelta、toXDelta属性

    2012-03-23 15:51 16144人阅读 评论(5) 收藏 举报 android <set xmlns:android="http://schemas.android.com ...

  6. Voting and Shuffling to Optimize Atomic Operations

    2iSome years ago I started work on my first CUDA implementation of the Multiparticle Collision Dynam ...

  7. Delphi下遍历文件夹下所有文件的递归算法

    {------------------------------------------------------------------------------- 过程名:    MakeFileLis ...

  8. mysql 统计sql

    1.按照月份统计数据 SELECT DATE_FORMAT(d.create_time,'%Y-%m') months,COUNT(id) AS scannum FROM detail d GROUP ...

  9. shell中字体变色

    在linux中给字体使用数字代码变色 字体颜色代码:重置0 ,黑色30,红色31,绿色32,黄色33,蓝色34,洋红35,青色36,浅灰37 效果代码:1m加粗  2m加下划线  5m闪动效果  7m ...

  10. slabtop 监控实时内核片缓存信息

                                        使用 slabtop命令监控实时内核片缓存信息                                 默认情况下,sl ...