Skip to content

Commit bff75b1

Browse files
author
lucifer
committed
feat: 电子书
1 parent 3a0b5d1 commit bff75b1

File tree

147 files changed

+1100
-1120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1100
-1120
lines changed

Diff for: .gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
.DS_Store
22
_book/
33
.idea/*
4-
node_modules/
4+
node_modules/
5+
book.pdf
6+
book.mobi
7+
book.epub
8+
book.zip

Diff for: README.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,36 @@
2626

2727
![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghluemaoj3j30z90dtmy5.jpg)
2828

29-
## 项目预览
29+
## 电子书
3030

31-
![project-overview](https://github.com/azl397985856/leetcode/blob/master/Kapture%202020-08-19%20at%2011.37.36.gif)
31+
这是我将我的所有公开的算法资料整理的一个电子书,全部题目信息中文化,以前会有一些英文描述。
3232

33-
可以清晰地看出仓库组织关系。
33+
![](https://cdn.jsdelivr.net/gh/azl397985856/cdn/2020-10-17/1602928846461-image.png)
3434

35-
(你可以下载本仓库 和 obsidian 软件,然后用 obsidian 打开获得更好的阅读效果)
35+
36+
![](https://cdn.jsdelivr.net/gh/azl397985856/cdn/2020-10-17/1602928862442-image.png)
37+
38+
我写这本电子书花费了大量的时间和精力,除了内容上的创作,还要做一些电子书的排版,以让大家获得更好的阅读体验。光数学公式的展示,我就研究了多个插件的要源码,并魔改了一下才使得导出的电子书支持 latex。 不过有些动图,在做成电子书的时候自然就变没了,如果需要看动图的, 可以去我的公众号《力扣加加》或者我的 leetcode 题解仓库看。
39+
40+
由于是电子书,因此阅读体验可能比 Github 更好, 但是相应地就不能获得及时的更新,因此你可以收藏一下我的同步电子书的网站 [西法的刷题秘籍 - 在线版](https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/)。后期可能将每日一题, 91 天学算法其他章节的讲义等也整理进来。
41+
42+
电子书有更新我也会在公众号《力扣加加》进行通知, 感兴趣的同学可以关注一下。
43+
44+
目前导出了四种格式,可惜的是这几种格式都有自己的不足:
45+
46+
- 在线版。 实时更新,想要及时获取最新信息的可以用在线版。
47+
- html。 方便大家在线观看,由于是 html ,实际上大家也可以保存起来**离线**观看。
48+
- pdf。可使用 pdf 阅读器和浏览器(比如谷歌)直接观看,阅读体验一般。
49+
- mobi。 下载一个 Kindle 客户端就可以看,不需要购买 Kindle。
50+
- epub。 数学公式和主题都比较不错, 但是代码没有高亮。
51+
52+
大家选择适合自己的格式下载即可。
53+
54+
- [在线版](https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/)
55+
- [html](./assets/book.zip)
56+
- [pdf](./book.pdf)
57+
- [mobi](./book.mobi)
58+
- [epub](./book.epub)
3659

3760
## 介绍
3861

@@ -167,7 +190,7 @@ leetcode 题解,记录自己的 leetcode 解题之路。
167190
- [《构造二叉树》专题](./selected/construct-binary-tree.md)
168191
- [字典序列删除](./selected/a-deleted.md)
169192
- [百度的算法面试题 - 祖玛游戏](./selected/zuma-game.md)
170-
- [西法带你学算法】一次搞定前缀和](./selected/atMostK.md)
193+
- [西法的刷题秘籍】一次搞定前缀和](./selected/atMostK.md)
171194
- [字节跳动的算法面试题是什么难度?](./selected/byte-dance-algo-ex.md)
172195
- [字节跳动的算法面试题是什么难度?(第二弹)](./selected/byte-dance-algo-ex-2017.md)
173196
- [《我是你的妈妈呀》 - 第一期](./selected/mother-01.md)

Diff for: SUMMARY.md

+213-214
Large diffs are not rendered by default.

Diff for: book.epub

-19.4 MB
Binary file not shown.

Diff for: book.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"structure": {
33
"readme": "introduction.md"
44
},
5-
"language": "zh-hans"
6-
5+
"language": "zh-hans",
6+
"plugins": ["katex", "ace", "theme-api"],
7+
"pluginsConfig": {
8+
"theme-api": {
9+
"theme": "dark"
10+
}
11+
}
712
}

Diff for: book.mobi

-23.1 MB
Binary file not shown.

Diff for: book.pdf

-48.2 MB
Binary file not shown.

Diff for: collections/easy.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 简单难度题目合集
2+
3+
这里的题目难度比较小, 大多是模拟题,或者是很容易看出解法的题目,另外简单题目一般使用暴力法都是可以解决的。 这个时候只有看一下数据范围,思考下你的算法复杂度就行了。
4+
5+
当然也不排除很多 hard 题目也可以暴力模拟,大家平时多注意数据范围即可。
6+
17
- [面试题 17.12. BiNode](../problems/binode-lcci.md) 🆕
28

39
- [0001.two-sum](https://github.com/azl397985856/leetcode/blob/master/problems/1.two-sum.md)

Diff for: collections/hard.md

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
# 困难难度题目合集
2+
3+
困难难度题目从类型上说多是:
4+
5+
-
6+
- 设计题
7+
- 游戏场景题目
8+
- 中等题目的 follow up
9+
10+
从解法上来说,多是:
11+
12+
- 图算法
13+
- 动态规划
14+
- 二分法
15+
- DFS & BFS
16+
- 状态压缩
17+
- 剪枝
18+
19+
从逻辑上说, 要么就是非常难想到,要么就是非常难写代码。 这里我总结了几个技巧:
20+
21+
1. 看题目的数据范围, 看能否暴力模拟
22+
2. 暴力枚举所有可能的算法往上套
23+
3. 总结和记忆解题模板,减少解题压力
24+
125
- [0004.median-of-two-sorted-array](../problems/4.median-of-two-sorted-arrays.md)
226
- [0023.merge-k-sorted-lists](../problems/23.merge-k-sorted-lists.md)
327
- [0025.reverse-nodes-in-k-group](../problems/25.reverse-nodes-in-k-groups-cn.md)

Diff for: collections/medium.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 中等难度题目合集
2+
3+
中等题目是力扣比例最大的部分,因此这部分我的题解也是最多的。 大家不要太过追求难题,先把中等难度题目做熟了再说。
4+
5+
这部分的题目要不需要我们挖掘题目的内含信息, 将其抽象成简单题目。 要么是一些写起来比较麻烦的题目, 一些人编码能力不行就挂了。因此大家一定要自己做, 即使看了题解”会了“,也要自己码一遍。自己不亲自写一遍,里面的细节永远不知道。
6+
17
- [面试题 17.09. 第 k 个数](../problems/get-kth-magic-number-lcci.md)
28

39
- [0002.add-two-numbers](../problems/2.add-two-numbers.md)
@@ -26,7 +32,7 @@
2632
- [0073.set-matrix-zeroes](../problems/73.set-matrix-zeroes.md)
2733
- [0075.sort-colors](../problems/75.sort-colors.md)
2834
- [0078.subsets](../problems/78.subsets.md)
29-
- [0079.word-search](../problems/79.word-search-en.md)
35+
- [0079.word-search](../problems/79.word-search.md)
3036
- [0080.remove-duplicates-from-sorted-array-ii](../problems/80.remove-duplicates-from-sorted-array-ii.md) 🆕
3137
- [0086.partition-list](../problems/86.partition-list.md)
3238
- [0090.subsets-ii](../problems/90.subsets-ii.md)

Diff for: cover.jpg

39.3 KB
Loading

Diff for: epilogue.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# 后记
2+
3+
以上就是本电子书的全部内容了。如果你觉得这本书对你有用, 那么请将它分享给你身边的朋友,你的点赞和分享是我最大的动力。另外由于本人水平和精力有限,难免有不正确的地方,大家可以通过 github 的 pr 给我指正,感谢大家。
4+
5+
后期的话文章会第一时间在公众号和我的博客更新,并定期整理到这个电子书中来。因此你可以关注我的公众号或者博客, 也可以关注我的同步电子书的网站 [西法的刷题秘籍 - 在线版](https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/) 获得内容的更新。
6+
7+
如果想加入读者交流群, 在公众号回复 leetcode 即可,西法在群里等着你。
8+
9+
关注公众号《力扣加加》带你啃下算法这块硬骨头。
10+
11+
![](https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs.jpg)
12+
13+
lucifer 的博客地址:https://lucifer.ren/blog/

Diff for: introduction.md

+28-3
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,40 @@
1111
- 2019-10-08: [纪念 LeetCode 项目 Star 突破 2W](./thanksGiving2.md),并且 Github 搜索“LeetCode”,排名第一。
1212

1313
- 2020-04-12: [项目突破三万 Star](./thanksGiving3.md)
14+
1415
- 2020-04-14: 官网`力扣加加`上线啦 💐💐💐💐💐,有专题讲解,每日一题,下载区和视频题解,后续会增加更多内容,还不赶紧收藏起来?地址:http://leetcode-solution.cn/
1516

1617
![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghluemaoj3j30z90dtmy5.jpg)
1718

1819
## 前言
1920

20-
这是我将我的所有公开的算法资料整理的一个电子书,主要特点有:
21+
这是我将我的所有公开的算法资料整理的一个电子书,全部题目信息中文化,以前会有一些英文描述,感谢 @CYL 的中文整理。
22+
23+
![](https://cdn.jsdelivr.net/gh/azl397985856/cdn/2020-10-17/1602928846461-image.png)
24+
25+
26+
![](https://cdn.jsdelivr.net/gh/azl397985856/cdn/2020-10-17/1602928862442-image.png)
27+
28+
我写这本电子书花费了大量的时间和精力,除了内容上的创作,还要做一些电子书的排版,以让大家获得更好的阅读体验。光数学公式的展示,我就研究了多个插件的要源码,并魔改了一下才使得导出的电子书支持 latex。 不过有些动图,在做成电子书的时候自然就变没了,如果需要看动图的, 可以去我的公众号《力扣加加》或者我的 leetcode 题解仓库看。
29+
30+
由于是电子书,因此阅读体验可能会更好, 但是相应地就不能获得及时的更新,因此你可以收藏一下我的同步电子书的网站 [西法的刷题秘籍 - 在线版](https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/)。后期可能将每日一题, 91 天学算法其他章节的讲义等也整理进来。
31+
32+
电子书有更新我也会在公众号《力扣加加》进行通知, 感兴趣的同学可以关注一下。
33+
34+
目前导出了四种格式,可惜的是这几种格式都有自己的不足:
35+
36+
- 在线版。 实时更新,想要及时获取最新信息的可以用在线版。
37+
- html。 方便大家在线观看,由于是 html ,实际上大家也可以保存起来**离线**观看。
38+
- pdf。可使用 pdf 阅读器和浏览器(比如谷歌)直接观看,阅读体验一般,生成的目录不能导航。
39+
- mobi。 下载一个 Kindle 客户端就可以看,不需要购买 Kindle。
40+
- epub。 数学公式和主题都比较不错, 但是代码没有高亮。
41+
42+
大家选择适合自己的格式下载即可。
43+
44+
- [在线版](https://leetcode-solution-leetcode-pp.gitbook.io/leetcode-solution/)
2145

22-
- 全部题目信息中文化,以前会有一些英文描述。
2346

24-
后期可能将每日一题也整理进来
47+
html, pdf,mobi 和 epub 格式,关注我的公众号《力扣加加》回复`电子书`即可
2548

2649
## 介绍
2750

@@ -63,6 +86,8 @@ leetcode 题解,记录自己的 leetcode 解题之路。
6386

6487
## 食用指南
6588

89+
- 我对大部分题目的复杂度都进行了分析,除了个别分析起来复杂的题目,大家一定要对一道题的复杂度了如指掌才可以。
90+
> 有些题目我是故意不写的, 比如所有的回溯题目我都没写, 不过它们全部都是指数的复杂度
6691
- 我对题目难度进行了分类的保留,因此你可以根据自己的情况刷。我推荐大家从简单开始,逐步加大难度,直到困难。
6792
- 这里有一张互联网公司面试中经常考察的问题类型总结的思维导图,我们可以结合图片中的信息分析一下。
6893

Diff for: package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"mathjax": "^2.7.6"
4+
}
5+
}

Diff for: problems/1.two-sum.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const twoSum = function (nums, target) {
7676
- 时间复杂度:$O(N)$
7777
- 空间复杂度:$O(N)$
7878

79-
更多题解可以访问我的LeetCode题解仓库:https://github.com/azl397985856/leetcode目前已经35K star啦。
79+
更多题解可以访问我的LeetCode题解仓库:https://github.com/azl397985856/leetcode目前已经37K star啦。
8080

8181
关注公众号力扣加加,努力用清晰直白的语言还原解题思路,并且有大量图解,手把手教你识别套路,高效刷题。
8282

Diff for: problems/101.symmetric-tree.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ class Solution:
119119
- 时间复杂度:$O(N)$,其中 N 为节点数。
120120
- 空间复杂度:递归的深度最高为节点数,因此空间复杂度是 $O(N)$,其中 N 为节点数。
121121

122-
更多题解可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 30K star 啦。
123-
124-
大家也可以关注我的公众号《脑洞前端》获取更多更新鲜的 LeetCode 题解
122+
大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
123+
大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。
124+
![](https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs.jpg)
125125

126126
![](https://tva1.sinaimg.cn/large/007S8ZIlly1ghlu9b4p9ej30x20iwjtf.jpg)

Diff for: problems/1011.capacity-to-ship-packages-within-d-days.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ var shipWithinDays = function(weights, D) {
174174
};
175175
```
176176

177-
## 扩展
177+
**复杂度分析**
178178

179-
## 参考
179+
- 时间复杂度:$O(logN)$
180+
- 空间复杂度:$O(N)$

Diff for: problems/1014.best-sightseeing-pair.md

+9
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ class Solution:
103103
pre = pre if pre > A[i] + i else A[i] + i
104104
return res
105105
```
106+
107+
**复杂度分析**
108+
109+
- 时间复杂度:$O(N)$
110+
- 空间复杂度:$O(N)$
111+
112+
大家对此有何看法,欢迎给我留言,我有时间都会一一查看回答。更多算法套路可以访问我的 LeetCode 题解仓库:https://github.com/azl397985856/leetcode 。 目前已经 37K star 啦。
113+
大家也可以关注我的公众号《力扣加加》带你啃下算法这块硬骨头。
114+
![](https://tva1.sinaimg.cn/large/007S8ZIlly1gfcuzagjalj30p00dwabs.jpg)

Diff for: problems/1015.smallest-integer-divisible-by-k.md

-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ class Solution:
9797
if mod == 0:
9898
return ix
9999
seen.add(mod)
100-
101-
# @lc code=end
102-
103-
104100
```
105101

106102
## 相关题目

Diff for: problems/1019.next-greater-node-in-linked-list.md

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class Solution:
103103
return res
104104
```
105105

106+
**复杂度分析**
107+
108+
其中 N 为链表的长度。
109+
110+
- 时间复杂度:$O(N)$
111+
- 空间复杂度:$O(N)$
112+
106113
## 扩展
107114

108115
甚至可以做到 O(1)的空间复杂度,请参考[C# O(n) time O(1) space](<https://leetcode.com/problems/next-greater-node-in-linked-list/discuss/267090/C-O(n)-time-O(1)-space>)

Diff for: problems/1020.number-of-enclaves.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ https://leetcode-cn.com/problems/number-of-enclaves/
1111
1212
返回网格中无法在任意次数的移动中离开网格边界的陆地单元格的数量。
1313
14-
 
1514
1615
示例 1:
1716
@@ -53,14 +52,14 @@ https://leetcode-cn.com/problems/number-of-enclaves/
5352

5453
- 如果遍历到 0,我们不予理会
5554
- 如果遍历到 1. 我们将其加到 temp
56-
- 我们不断拓展边界(上下左右)
57-
- 如果 dfs 过程中碰到了边界,说明我们可以逃脱,我们将累加的 temp 清空
58-
- 如果 dfs 过程之后没有碰到边界,说明我们无法逃脱。我们将 temp 加到 cnt
55+
- 不断拓展边界(上下左右)
56+
- 如果 dfs 过程中碰到了边界,说明可以逃脱,我们将累加的 temp 清空
57+
- 如果 dfs 过程之后没有碰到边界,说明无法逃脱。我们将 temp 加到 cnt
5958
- 最终返回 cnt 即可
6059

6160
### 关键点解析
6261

63-
- visited 记录访问过的节点,防止重复计算
62+
- visited 记录访问过的节点,防止无限循环。
6463

6564
### 代码
6665

@@ -102,6 +101,11 @@ class Solution:
102101

103102
```
104103

104+
**复杂度分析**
105+
106+
- 时间复杂度:$O(M * N)$
107+
- 空间复杂度:$O(M * N)$
108+
105109
## 解法二 (消除法)
106110

107111
## 公司
@@ -110,7 +114,7 @@ class Solution:
110114

111115
### 思路
112116

113-
上面的解法时间复杂度和空间复杂度都很差,我们考虑进行优化, 这里我们使用消除法。
117+
上面的解法空间复杂度很差,我们考虑进行优化, 这里我们使用消除法。即使用题目范围外的数据原地标记是否访问, 这样时间复杂度可以优化到 $O(1)$,这是一种非常常见的优化技巧,请务必掌握,另外文章末尾的题目也是类似的技巧,大家可以结合起来练习
114118

115119
- 从矩阵边界开始 dfs
116120
- 如果碰到 1 就将其变成 0
@@ -167,6 +171,11 @@ class Solution:
167171

168172
```
169173

174+
**复杂度分析**
175+
176+
- 时间复杂度:$O(M * N)$
177+
- 空间复杂度:$O(1)$
178+
170179
## 参考
171180

172181
- [200.number-of-islands](https://github.com/azl397985856/leetcode/blob/master/problems/200.number-of-islands.md)

Diff for: problems/1023.camelcase-matching.md

+7
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ class Solution:
135135
return res
136136
```
137137

138+
**复杂度分析**
139+
140+
其中 N 为 queries 的长度, M 为 queries 的平均长度, P 为 pattern 的长度。
141+
142+
- 时间复杂度:$O(N * M * P)$
143+
- 空间复杂度:$O(1)$
144+
138145
## 扩展
139146

140147
这是一个符合直觉的解法,但是却不是一个很优秀的解法,那么你有想到什么优秀的解法么?

0 commit comments

Comments
 (0)