535. Encode and Decode TinyURL 长短URL
[抄题]:
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的更多相关文章
- 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
Question: TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/pro ...
- 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 ...
- [LeetCode] 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 ...
- 535 Encode and Decode TinyURL 编码和解码精简URL地址
详见:https://leetcode.com/problems/encode-and-decode-tinyurl/description/ C++: class Solution { public ...
- 535. Encode and Decode TinyURL
▶ 要求给出一种对 URL 网址进行压缩和解压的算法,例如 https://leetcode.com/problems/design-tinyurl ←→ http://tinyurl.com/4e9 ...
- [LeetCode] Encode and Decode TinyURL 编码和解码精简URL地址
Note: This is a companion problem to the System Design problem: Design TinyURL. TinyURL is a URL sho ...
随机推荐
- 为什么要编写轻量级的View Controller??
1.作为iOS项目中最大的文件,ViewControllers中的代码复用率几乎是最低的2.重量级的View COntroller加大了测试的复杂度.所以关注ViewController的瘦身,把业务 ...
- 【BZOJ2850】巧克力王国 KDtree
[BZOJ2850]巧克力王国 Description 巧克力王国里的巧克力都是由牛奶和可可做成的.但是并不是每一块巧克力都受王国人民的欢迎,因为大家都不喜 欢过于甜的巧克力.对于每一块巧克力,我们设 ...
- heartbeat测试
节点名: node-master 192.168.1.77 node-slave 192.168.1.88 VIP 192.168.1.234 带下划线的不允许作为节点名 修改节点名字 gvim /e ...
- 【转】Jmeter:图形界面压力测试工具
Jmeter是一款强大的图形界面压力测试工具,完全用Java写成,关于Jmeter的介绍,网上其实有不少的文章,我原本是不想再重复写类似文章的,但我发现有些很关键性的,在我们测试中一定会用到的一些设置 ...
- juc线程池原理(六):jdk线程池中的设计模式
一.jdk中默认线程池中的代理模式 单例类线程池只有一个线程,无边界队列,适合cpu密集的运算.jdk中创建线程池是通过Executors类中提供的静态的方法来创建的,其中的单例类线程池的方法如下: ...
- AngularJS:Scope(作用域)
ylbtech-AngularJS:Scope(作用域) 1.返回顶部 1. AngularJS Scope(作用域) Scope(作用域) 是应用在 HTML (视图) 和 JavaScript ( ...
- Spring XML和Annotation混合配置的时候,XML中Bean名称写错会导致启动异常不打印、死循环
今天做Tomcat迁移Spring Boot,遇到一个坑.启动没有错误,CPU特别高 经过把堆栈kill -3 打印出来,发现堆栈特别长(没有死循环),所有的堆栈信息都集中在org.springfra ...
- 记一次oralce 11g r2 rac安装问题
环境:虚拟机[root@rac1 ~]# lsb_release -aLSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd6 ...
- MFC调试的几个技巧
TCHAR pStr[] = _T("this is a test!"); void* p = (void*)pStr; TRACE(_T("pStr is %s\n&q ...
- log4net 使用总结- (1)在ASP.NET MVC 中使用
1. 去官网下载log4net.dll,增加引用到站点下(你也可以通过nuget 安装) http://logging.apache.org/log4net/download_log4net.cgi ...