Leetcode 简略题解 - 共567题

 
 
写在开头:我作为一个老实人,一向非常反感骗赞、收智商税两种行为。前几天看到不止两三位用户说自己辛苦写了干货,结果收藏数是点赞数的三倍有余,感觉自己的无偿付出连认同都得不到,很是失望。明白人都知道这是潜水伸手党的锅。但同时,截止写这段话时,我发现这篇Leetcode简略(得不能再简略的)题解得到了一千多赞,三千多收藏。所以,在我不向任何人做任何广告、收任何费用的前提下,麻烦在收藏的同时,顺手点个赞(对只收藏不点赞的行为表示明确鄙视)。如果连点一个赞的力气都没有,恐怕Leetcode也就甭刷了。拒绝伸手党,从你我做起。
// To begin with: I for one as an honest man, am always loath at the thought of luring upvotes or making profit from stupid taxes. A few days ago, I saw more than a few zhihuers uttering their disappointment with their informative answers receiving three times as much bookmarks as upvotes. It takes no more than a halfwit to see that lurks are to blame. However, as of the moment of me writing this, this so very brief (hardly more so) summary of Leetcode solutions has around 1k upvotes and 3k bookmarks. Being willing to share things for free requires nothing but a little bit of encouragement and recognition. As such, I recommend those who choose to "bookmark" to add one extra click on the "upvote" button (my sincere despise to all ungrateful lurks), considering the fact that I ain't pushing no ads or charging no fees to nobody. IMO, you don't quite stand a chance against hundreds of Leetcode problems if you lack the strength for a mere "upvote". No bloodsucker, your choice matters.
这是一篇由用户 @朱里 整理的Leetcode题解。就是我。
// This is a memo for Leetcode problem set, by user @朱里. That's me.
其中的题解部分会不定期更新,因为题目实在太多了,一次并不能写完。
// As the number of problems is massive, I'll keep updating this article every once in a while. You don't expect me getting it done overnight, do you?
目前已写完567题的题解。
// Current progress is 567/585.
目前LeetCode出新题比较频繁。鉴于付费题目需要交钱才能刷,我打算攒到一两百题再掏钱。毕竟掏了一个月的钱,一个星期就刷完了,不怎么划算。按照目前LeetCode题目的难度和质量来看,每次出新题,基本都能马上搞定,毕竟刷了几百题,也很难再有什么新花样了。
// Currently LeetCode is updating problems at a fast and steady pace. The premium problems are unlocked only after payment, so I decide to take my order when there're a hundred or two available. Basically I don't deem the price quite worth, as you usually finish them off in a week while the payment is for a month. Free problems are fine, just no surprise for me anymore after doing five hundreds of them, I guess.
有人常常花很多时间。考虑做一件事“有什么用”?你猜我怎么想,“没什么卵用”。
// People tend to waste a lot of time think about the meaning of everything. Know what I think? Nothing. No, none, null, void.
活着、读书、上学、工作、找个人结婚、安顿下来、放弃一切理想信仰希望、混日子、变老、等死。有意义吗?没有意义吗?
// Live, go to school, be young and foolish, get a job, get laid, settle down, give up your dreams, beliefs and hopes, grow up into a nobody, turn old and stubborn, wither and die. What's the point? What's not?
所以,刷几百道Leetcode,一定能找到工作吗?别tm废话了,刷吧。
// So, will Leetcode land me a job after all? Tell you what, just shut the f**k up and do it.
为什么人生如此艰难?不为什么。
// Life is tough, with or without you asking why.
所有题中,有大约10题左右不是独立完成,参考了网上高手的解法。调试用脑子或者纸笔。基本不使用IDE,不编译运行。
// Among these problems, around 10 were solved after referencing clever solutions from the Internet, the rest were all solved independently. Code was debugged inside my brain or on paper. IDE or compiler were hardly involved.
总体上,代码尽量追求可读性,保证时间空间复杂度的优化,并保持风格一致。
// In general, readability is what I care more about (compared to code length). Time and space complexity are bottom line. Consistent code style is maintained at best efforts.
感觉现在面试题的难度也有种“通货膨胀”的趋势,以前的“hard”题目和现在的“medium”差不多,看来工作真是越来越难找了。
// There seem to be inflation in tech interview problems as well (AFAIK prices never go down). Those rated "medium" today are no easier than those rated "hard" in the old days. Harder to make a living, isn't it?
代码库地址:zhuli19901106/leetcode-2
// Code repo can be found at zhuli19901106/leetcode-2.
关于很多题为什么一句话(甚至一个词)带过,简言之就是“典型题”。因为一个经过合格训练的程序员对于两百行以内的算法代码应该有足够的代码阅读能力,以及快速适应新语言的能力。每题的Github代码足够提供参考。对于关键思路做最少的提示即可,这也是面试所能容忍的程度。超出此程度,免不了被淘汰。在不涉及软件工程、设计模式、模块接口设计的情况下,逐字逐句解释并且配上插图毫无必要。同时,能五到十分钟解决的题,是不值得花二十分钟写题解的。刷一题发一篇文章,你是打算孤独终老?还是干点儿别的吧。
// As for why most problems are walked through by a mere sentence (even a single word), simply put, they're just typical. I think a programmer with proper training should have adequate competence of code reading and adaptability to new languages. The given codes on Github are sufficient for the task of illustration. Minimal hints on the key idea is what I deem tolerable for a real interview. Beyond that, you fail. Without involvement of software engineering, design patterns or modular interface designs, a word-by-word explanation with illustration is totally tedious. Besides, a five-minute kill is not worth a twenty-minute autopsy. A post for every problem solved, serious? Looking to die alone playing Leetcode? There are better things to do for sure.
下面以题号为顺序,对每一题的题意和解法做简要描述:
// Following here is a summary of description and solution for every problem I solved:
写题解的目的只是用于备忘和加深理解,所以有没有人看并不重要。
// It's just a memo to help fortify comprehension. Ain't no big deal if nobody's reading this.
如果有人看了后,觉得我某道题的解法有值得讨论或者错误的地方,欢迎在评论里指出。
// Should anyone feel the need for discussion, please leave your comment.
以下是更新日志:
// Change logs are as follows:
截止2017年3月11日02:25,Leetcode的Algorithm部分(包括付费题目)总共491题。
// As of the moment 02:25, 2017.3.11, there're altogether 491 problems in the Algorithm section of Leetcode.
截止2017年3月23日05:02,Leetcode的Algorithm部分(包括付费题目)总共499题。
// As of the moment 05:02, 2017.3.23, there're altogether 499 problems in the Algorithm section of Leetcode.
截止2017年4月26日15:01,Leetcode的Algorithm部分(包括付费题目)总共519题。
// As of the moment 15:01, 2017.4.26, there're altogether 519 problems in the Algorithm section of Leetcode.
截止2017年5月3日11:13,Leetcode的Algorithm部分(包括付费题目)总共523题。
// As of the moment 11:13, 2017.5.3, there're altogether 523 problems in the Algorithm section of Leetcode.
截止2017年5月26日21:08,Leetcode的Algorithm部分(包括付费题目)总共535题。
// As of the moment 21:08, 2017.5.26, there're altogether 535 problems in the Algorithm section of Leetcode.
截止2017年6月10日16:52,Leetcode的Algorithm部分(包括付费题目)总共543题。
// As of the moment 16:52, 2017.6.10, there're altogether 543 problems in the Algorithm section of Leetcode.
截止2017年8月14日10:33,Leetcode的Algorithm部分(包括付费题目)总共585题。
// As of the moment 10:33, 2017.8.14, there're altogether 585 problems in the Algorithm section of Leetcode.

Leetcode 简略题解 - 共567题的更多相关文章

  1. 【LeetCode】堆 heap(共31题)

    链接:https://leetcode.com/tag/heap/ [23] Merge k Sorted Lists [215] Kth Largest Element in an Array (无 ...

  2. 【LeetCode】排序 sort(共20题)

    链接:https://leetcode.com/tag/sort/ [56]Merge Intervals (2019年1月26日,谷歌tag复习) 合并区间 Input: [[1,3],[2,6], ...

  3. 【LeetCode】数学(共106题)

    [2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/979 ...

  4. 【LeetCode】哈希表 hash_table(共88题)

    [1]Two Sum (2018年11月9日,k-sum专题,算法群衍生题) 给了一个数组 nums, 和一个 target 数字,要求返回一个下标的 pair, 使得这两个元素相加等于 target ...

  5. 【LeetCode】BFS(共43题)

    [101]Symmetric Tree 判断一棵树是不是对称. 题解:直接递归判断了,感觉和bfs没有什么强联系,当然如果你一定要用queue改写的话,勉强也能算bfs. // 这个题目的重点是 比较 ...

  6. 【LeetCode】分治法 divide and conquer (共17题)

    链接:https://leetcode.com/tag/divide-and-conquer/ [4]Median of Two Sorted Arrays [23]Merge k Sorted Li ...

  7. 【LeetCode】线段树 segment-tree(共9题)+ 树状数组 binary-indexed-tree(共5题)

    第一部分---线段树:https://leetcode.com/tag/segment-tree/ [218]The Skyline Problem [307]Range Sum Query - Mu ...

  8. 【LeetCode】二分 binary_search(共58题)

    [4]Median of Two Sorted Arrays [29]Divide Two Integers [33]Search in Rotated Sorted Array [34]Find F ...

  9. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

随机推荐

  1. 编程思想的理解(POP,OOP,SOA,AOP) x

    http://blog.chinaunix.net/uid-29417436-id-4060980.html 1)POP--面向过程编程(Process-oriented programming ): ...

  2. 【洛谷5279】[ZJOI2019] 麻将(“胡牌自动机”上DP)

    点此看题面 大致题意: 给你13张麻将牌,问你期望再摸多少张牌可以满足存在一个胡的子集. 似乎ZJOI2019Day1的最大收获是知道了什么是胡牌? 一个显然的性质 首先我们要知道一个显然的性质,即对 ...

  3. ACM-ICPC (10/19)

    这两天在看虚树,的确很难理解. 不过大致的思路就是说删掉一些没有用的点,但是仍然保持树的相对结构,树上只有两种点,一个是集合点,和一些LCA,这些LCA是为了保持树的相对结构,才留下的. 具体做法网上 ...

  4. 【PHP后台】接入支付宝

     我使用PHP主要是为客户端做后台使用,并不会做前端网页.   这两天因为公司项目需要,必须接入支付功能,而支付宝当然首当其冲,考虑迭代版本的需要,首先接入支付宝功能,其他的支付功能以后迭代版本的时候 ...

  5. c++字符串初始化

    #include<string> string s1 = "abcdefg"; string s2("abcdefg");

  6. JavaScript内存管理

    低级语言,比如C,有低级的内存管理基元,想malloc(),free().另一方面,JavaScript的内存基元在变量(对象,字符串等等)创建时分配,然后在他们不再被使用时"自动" ...

  7. HDFS副本存放读取

    HDFS作为Hadoop中 的一个分布式文件系统,而且是专门为它的MapReduce设计,所以HDFS除了必须满足自己作为分布式文件系统的高可靠性外,还必须为 MapReduce提供高效的读写性能,那 ...

  8. PLSQL 禁用所有约束,启用约束,索引,触发器等

    --禁用外键和触发器 SET SERVEROUTPUT ON SIZE 50000BEGINfor c in (select 'ALTER TABLE '||TABLE_NAME||' DISABLE ...

  9. iOS 获取APP的CPU、内存等信息

    目标是开发一个SDK,嵌入到APP里面,用来统计当前APP的实时CPU.内存等信息 2015.11.17 http://stackoverflow.com/questions/12889422/ios ...

  10. iOS之蓝牙开发—CoreBluetooth详解

    CoreBluetooth的API是基于BLE4.0的标准的.这个框架涵盖了BLE标准的所有细节.仅仅只有新的iOS设备和Mac是和BLE标准兼容.在CoreBluetooth框架中,有两个主要的角色 ...