[抄题]:

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));

最新文章

  1. 在as3中使用protobuf
  2. linux出现user account has expired解决方案
  3. ambari无法登陆 设备空间不足
  4. C++的优秀特性6:智能指针
  5. JMX笔记(一)
  6. &lt;base target=&quot;_blank&quot;/&gt;
  7. get-random生成电话号码
  8. 解决CentOS虚拟机克隆后无法上网(网卡信息不一致)的问题
  9. 侯捷STL学习(二)
  10. 【转】Wi-Fi 20mhz 和 40mhz 频段带宽的区别是什么?
  11. 从底层角度看ASP.NET-A low-level Look at the ASP.NET...
  12. Java读取txt文件和写入txt文件
  13. eclipse 工作区空格和回车键显示为乱码
  14. Django:安装和启动
  15. mpvue——引入antv-F2图表
  16. ubuntu14.04 mysql数据库允许远程访问设置
  17. FPGA - 认识FPGA
  18. alpha阶段 代码结构及技术难点简介
  19. 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT)
  20. jQuery框架-3.jQuery自定义封装插件和第三方插件

热门文章

  1. 【转】 史上最详尽的平衡树(splay)讲解与模板(非指针版spaly)
  2. JDBC 3 通过PreparedStatement 对数据库进行增删改查
  3. #507. 「LibreOJ NOI Round #1」接竹竿 dp
  4. TortoiseGit不同分支合并代码
  5. Java文件压缩优化工具(ProGuard) 软件介绍 Soft content
  6. JS Date日期
  7. 理解contextmanager
  8. 多路复用IO
  9. C#中Monitor对象与Lock关键字的区别分析
  10. python&#39;s twenty-sixth day for me 模块