Skip to content

Commit 86a0208

Browse files
替换图片链接
1 parent 91e7dab commit 86a0208

File tree

216 files changed

+813
-813
lines changed

Some content is hidden

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

216 files changed

+813
-813
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181

182182

183183
题目分类大纲如下:
184-
<img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20240424172231.png' width=600 alt='二叉树大纲'> </img></div>
184+
<img src='https://file.kamacoder.com/pics/20240424172231.png' width=600 alt='二叉树大纲'> </img></div>
185185

186186
1. [关于二叉树,你该了解这些!](./problems/二叉树理论基础.md)
187187
2. [二叉树:二叉树的递归遍历](./problems/二叉树的递归遍历.md)
@@ -222,7 +222,7 @@
222222

223223
题目分类大纲如下:
224224

225-
<img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20240424172311.png' width=600 alt='回溯算法大纲'> </img></div>
225+
<img src='https://file.kamacoder.com/pics/20240424172311.png' width=600 alt='回溯算法大纲'> </img></div>
226226

227227
1. [关于回溯算法,你该了解这些!](./problems/回溯算法理论基础.md)
228228
2. [回溯算法:77.组合](./problems/0077.组合.md)
@@ -252,7 +252,7 @@
252252
题目分类大纲如下:
253253

254254

255-
<img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210917104315.png' width=600 alt='贪心算法大纲'> </img></div>
255+
<img src='https://file.kamacoder.com/pics/20210917104315.png' width=600 alt='贪心算法大纲'> </img></div>
256256

257257
1. [关于贪心算法,你该了解这些!](./problems/贪心算法理论基础.md)
258258
2. [贪心算法:455.分发饼干](./problems/0455.分发饼干.md)
@@ -503,5 +503,5 @@
503503

504504
添加微信记得备注,如果是已工作,备注:姓名-城市-岗位。如果学生,备注:姓名-学校-年级。**备注没有自我介绍不通过哦**
505505

506-
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/第二企业刷题活码.png" data-img="1" width="200" height="200"></img></div>
506+
<div align="center"><img src="https://file.kamacoder.com/pics/第二企业刷题活码.png" data-img="1" width="200" height="200"></img></div>
507507

problems/0001.两数之和.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ map目的用来存放我们访问过的元素,因为遍历数组的时候,
8383

8484
过程如下:
8585

86-
![过程一](https://code-thinking-1253855093.file.myqcloud.com/pics/20220711202638.png)
86+
![过程一](https://file.kamacoder.com/pics/20220711202638.png)
8787

8888

89-
![过程二](https://code-thinking-1253855093.file.myqcloud.com/pics/20230220223536.png)
89+
![过程二](https://file.kamacoder.com/pics/20230220223536.png)
9090

9191
C++代码:
9292

problems/0005.最长回文子串.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ dp[i][j]可以初始化为true么? 当然不行,怎能刚开始就全都匹
106106

107107
dp[i + 1][j - 1] 在 dp[i][j]的左下角,如图:
108108

109-
![647.回文子串](https://code-thinking-1253855093.file.myqcloud.com/pics/20210121171032473.jpg)
109+
![647.回文子串](https://file.kamacoder.com/pics/20210121171032473.jpg)
110110

111111
如果这矩阵是从上到下,从左到右遍历,那么会用到没有计算过的dp[i + 1][j - 1],也就是根据不确定是不是回文的区间[i+1,j-1],来判断了[i,j]是不是回文,那结果一定是不对的。
112112

@@ -140,7 +140,7 @@ for (int i = s.size() - 1; i >= 0; i--) { // 注意遍历顺序
140140

141141
举例,输入:"aaa",dp[i][j]状态如下:
142142

143-
![647.回文子串1](https://code-thinking-1253855093.file.myqcloud.com/pics/20210121171059951.jpg)
143+
![647.回文子串1](https://file.kamacoder.com/pics/20210121171059951.jpg)
144144

145145
**注意因为dp[i][j]的定义,所以j一定是大于等于i的,那么在填充dp[i][j]的时候一定是只填充右上半部分**
146146

problems/0017.电话号码的字母组合.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。
1313

14-
![17.电话号码的字母组合](https://code-thinking-1253855093.file.myqcloud.com/pics/2020102916424043.png)
14+
![17.电话号码的字母组合](https://file.kamacoder.com/pics/2020102916424043.png)
1515

1616
示例:
1717
* 输入:"23"
@@ -64,7 +64,7 @@ const string letterMap[10] = {
6464

6565
例如:输入:"23",抽象为树形结构,如图所示:
6666

67-
![17. 电话号码的字母组合](https://code-thinking-1253855093.file.myqcloud.com/pics/20201123200304469.png)
67+
![17. 电话号码的字母组合](https://file.kamacoder.com/pics/20201123200304469.png)
6868

6969
图中可以看出遍历的深度,就是输入"23"的长度,而叶子节点就是我们要收集的结果,输出["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
7070

problems/0019.删除链表的倒数第N个节点.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
示例 1:
1717

1818

19-
![19.删除链表的倒数第N个节点](https://code-thinking-1253855093.file.myqcloud.com/pics/20210510085957392.png)
19+
![19.删除链表的倒数第N个节点](https://file.kamacoder.com/pics/20210510085957392.png)
2020

2121
输入:head = [1,2,3,4,5], n = 2
2222
输出:[1,2,3,5]

problems/0020.有效的括号.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ cd a/b/c/../../
8181

8282

8383
1. 第一种情况,字符串里左方向的括号多余了 ,所以不匹配。
84-
![括号匹配1](https://code-thinking-1253855093.file.myqcloud.com/pics/2020080915505387.png)
84+
![括号匹配1](https://file.kamacoder.com/pics/2020080915505387.png)
8585

8686
2. 第二种情况,括号没有多余,但是 括号的类型没有匹配上。
87-
![括号匹配2](https://code-thinking-1253855093.file.myqcloud.com/pics/20200809155107397.png)
87+
![括号匹配2](https://file.kamacoder.com/pics/20200809155107397.png)
8888

8989
3. 第三种情况,字符串里右方向的括号多余了,所以不匹配。
90-
![括号匹配3](https://code-thinking-1253855093.file.myqcloud.com/pics/20200809155115779.png)
90+
![括号匹配3](https://file.kamacoder.com/pics/20200809155115779.png)
9191

9292

9393

problems/0035.搜索插入位置.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
这道题目,要在数组中插入目标值,无非是这四种情况。
4343

44-
![35_搜索插入位置3](https://code-thinking-1253855093.file.myqcloud.com/pics/20201216232148471.png)
44+
![35_搜索插入位置3](https://file.kamacoder.com/pics/20201216232148471.png)
4545

4646
* 目标值在数组所有元素之前
4747
* 目标值等于数组中某一个元素
@@ -82,14 +82,14 @@ public:
8282
8383
效率如下:
8484
85-
![35_搜索插入位置](https://code-thinking-1253855093.file.myqcloud.com/pics/20201216232127268.png)
85+
![35_搜索插入位置](https://file.kamacoder.com/pics/20201216232127268.png)
8686
8787
### 二分法
8888
8989
既然暴力解法的时间复杂度是O(n),就要尝试一下使用二分查找法。
9090
9191
92-
![35_搜索插入位置4](https://code-thinking-1253855093.file.myqcloud.com/pics/202012162326354.png)
92+
![35_搜索插入位置4](https://file.kamacoder.com/pics/202012162326354.png)
9393
9494
大家注意这道题目的前提是数组是有序数组,这也是使用二分查找的基础条件。
9595
@@ -99,7 +99,7 @@ public:
9999
100100
大体讲解一下二分法的思路,这里来举一个例子,例如在这个数组中,使用二分法寻找元素为5的位置,并返回其下标。
101101
102-
![35_搜索插入位置5](https://code-thinking-1253855093.file.myqcloud.com/pics/20201216232659199.png)
102+
![35_搜索插入位置5](https://file.kamacoder.com/pics/20201216232659199.png)
103103
104104
二分查找涉及的很多的边界条件,逻辑比较简单,就是写不好。
105105
@@ -150,7 +150,7 @@ public:
150150
* 空间复杂度:O(1)
151151

152152
效率如下:
153-
![35_搜索插入位置2](https://code-thinking-1253855093.file.myqcloud.com/pics/2020121623272877.png)
153+
![35_搜索插入位置2](https://file.kamacoder.com/pics/2020121623272877.png)
154154

155155
### 二分法第二种写法
156156

problems/0037.解数独.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。
1919
空白格用 '.' 表示。
2020

21-
![解数独](https://code-thinking-1253855093.file.myqcloud.com/pics/202011171912586.png)
21+
![解数独](https://file.kamacoder.com/pics/202011171912586.png)
2222

2323
一个数独。
2424

25-
![解数独](https://code-thinking-1253855093.file.myqcloud.com/pics/20201117191340669.png)
25+
![解数独](https://file.kamacoder.com/pics/20201117191340669.png)
2626

2727
答案被标成红色。
2828

@@ -52,7 +52,7 @@
5252

5353
因为这个树形结构太大了,我抽取一部分,如图所示:
5454

55-
![37.解数独](https://code-thinking-1253855093.file.myqcloud.com/pics/2020111720451790-20230310131816104.png)
55+
![37.解数独](https://file.kamacoder.com/pics/2020111720451790-20230310131816104.png)
5656

5757

5858
### 回溯三部曲
@@ -83,7 +83,7 @@ bool backtracking(vector<vector<char>>& board)
8383
8484
* 递归单层搜索逻辑
8585
86-
![37.解数独](https://code-thinking-1253855093.file.myqcloud.com/pics/2020111720451790-20230310131822254.png)
86+
![37.解数独](https://file.kamacoder.com/pics/2020111720451790-20230310131822254.png)
8787
8888
在树形图中可以看出我们需要的是一个二维的递归 (一行一列)
8989

problems/0039.组合总和.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ candidates 中的数字可以无限制重复被选取。
5050

5151
本题搜索的过程抽象成树形结构如下:
5252

53-
![39.组合总和](https://code-thinking-1253855093.file.myqcloud.com/pics/20201223170730367.png)
53+
![39.组合总和](https://file.kamacoder.com/pics/20201223170730367.png)
5454
注意图中叶子节点的返回条件,因为本题没有组合数量要求,仅仅是总和的限制,所以递归没有层数的限制,只要选取的元素总和超过target,就返回!
5555

5656
而在[77.组合](https://programmercarl.com/0077.组合.html)[216.组合总和III](https://programmercarl.com/0216.组合总和III.html) 中都可以知道要递归K层,因为要取k个元素的组合。
@@ -85,7 +85,7 @@ void backtracking(vector<int>& candidates, int target, int sum, int startIndex)
8585
8686
在如下树形结构中:
8787
88-
![39.组合总和](https://code-thinking-1253855093.file.myqcloud.com/pics/20201223170730367-20230310135337214.png)
88+
![39.组合总和](https://file.kamacoder.com/pics/20201223170730367-20230310135337214.png)
8989
9090
从叶子节点可以清晰看到,终止只有两种情况,sum大于target和sum等于target。
9191
@@ -158,7 +158,7 @@ public:
158158
159159
在这个树形结构中:
160160
161-
![39.组合总和](https://code-thinking-1253855093.file.myqcloud.com/pics/20201223170730367-20230310135342472.png)
161+
![39.组合总和](https://file.kamacoder.com/pics/20201223170730367-20230310135342472.png)
162162
163163
以及上面的版本一的代码大家可以看到,对于sum已经大于target的情况,其实是依然进入了下一层递归,只是下一层递归结束判断的时候,会判断sum > target的话就返回。
164164
@@ -171,7 +171,7 @@ public:
171171
如图:
172172
173173
174-
![39.组合总和1](https://code-thinking-1253855093.file.myqcloud.com/pics/20201223170809182.png)
174+
![39.组合总和1](https://file.kamacoder.com/pics/20201223170809182.png)
175175
176176
for循环剪枝代码如下:
177177

problems/0040.组合总和II.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ candidates 中的每个数字在每个组合中只能使用一次。
7676

7777
选择过程树形结构如图所示:
7878

79-
![40.组合总和II](https://code-thinking-1253855093.file.myqcloud.com/pics/20230310000918.png)
79+
![40.组合总和II](https://file.kamacoder.com/pics/20230310000918.png)
8080

8181
可以看到图中,每个节点相对于 [39.组合总和](https://mp.weixin.qq.com/s/FLg8G6EjVcxBjwCbzpACPw)我多加了used数组,这个used数组下面会重点介绍。
8282

@@ -126,7 +126,7 @@ if (sum == target) {
126126

127127
这块比较抽象,如图:
128128

129-
![40.组合总和II1](https://code-thinking-1253855093.file.myqcloud.com/pics/20230310000954.png)
129+
![40.组合总和II1](https://file.kamacoder.com/pics/20230310000954.png)
130130

131131
我在图中将used的变化用橘黄色标注上,可以看出在candidates[i] == candidates[i - 1]相同的情况下:
132132

@@ -137,7 +137,7 @@ if (sum == target) {
137137

138138
而 used[i - 1] == true,说明是进入下一层递归,去下一个数,所以是树枝上,如图所示:
139139

140-
![](https://code-thinking-1253855093.file.myqcloud.com/pics/20221021163812.png)
140+
![](https://file.kamacoder.com/pics/20221021163812.png)
141141

142142

143143
**这块去重的逻辑很抽象,网上搜的题解基本没有能讲清楚的,如果大家之前思考过这个问题或者刷过这道题目,看到这里一定会感觉通透了很多!**

problems/0042.接雨水.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
首先要明确,要按照行来计算,还是按照列来计算。
4848

4949
按照行来计算如图:
50-
![42.接雨水2](https://code-thinking-1253855093.file.myqcloud.com/pics/20210402091118927.png)
50+
![42.接雨水2](https://file.kamacoder.com/pics/20210402091118927.png)
5151

5252
按照列来计算如图:
53-
![42.接雨水1](https://code-thinking-1253855093.file.myqcloud.com/pics/20210402091208445.png)
53+
![42.接雨水1](https://file.kamacoder.com/pics/20210402091208445.png)
5454

5555
一些同学在实现的时候,很容易一会按照行来计算一会按照列来计算,这样就会越写越乱。
5656

@@ -62,7 +62,7 @@
6262

6363
这句话可以有点绕,来举一个理解,例如求列4的雨水高度,如图:
6464

65-
![42.接雨水3](https://code-thinking-1253855093.file.myqcloud.com/pics/20210223092732301.png)
65+
![42.接雨水3](https://file.kamacoder.com/pics/20210223092732301.png)
6666

6767
列4 左侧最高的柱子是列3,高度为2(以下用lHeight表示)。
6868

@@ -201,7 +201,7 @@ public:
201201

202202
1. 首先单调栈是按照行方向来计算雨水,如图:
203203

204-
![42.接雨水2](https://code-thinking-1253855093.file.myqcloud.com/pics/20210223092629946.png)
204+
![42.接雨水2](https://file.kamacoder.com/pics/20210223092629946.png)
205205

206206
知道这一点,后面的就可以理解了。
207207

@@ -215,7 +215,7 @@ public:
215215

216216
如图:
217217

218-
![42.接雨水4](https://code-thinking-1253855093.file.myqcloud.com/pics/2021022309321229.png)
218+
![42.接雨水4](https://file.kamacoder.com/pics/2021022309321229.png)
219219

220220
关于单调栈的顺序给大家一个总结: [739. 每日温度](https://programmercarl.com/0739.每日温度.html) 中求一个元素右边第一个更大元素,单调栈就是递增的,[84.柱状图中最大的矩形](https://programmercarl.com/0084.柱状图中最大的矩形.html)求一个元素右边第一个更小元素,单调栈就是递减的。
221221

@@ -229,7 +229,7 @@ public:
229229

230230
如图所示:
231231

232-
![42.接雨水5](https://code-thinking-1253855093.file.myqcloud.com/pics/20210223094619398.png)
232+
![42.接雨水5](https://file.kamacoder.com/pics/20210223094619398.png)
233233

234234
4. 栈里要保存什么数值
235235

@@ -284,7 +284,7 @@ if (height[i] == height[st.top()]) { // 例如 5 5 1 7 这种情况
284284

285285
如果当前遍历的元素(柱子)高度大于栈顶元素的高度,此时就出现凹槽了,如图所示:
286286

287-
![42.接雨水4](https://code-thinking-1253855093.file.myqcloud.com/pics/2021022309321229-20230310123027977.png)
287+
![42.接雨水4](https://file.kamacoder.com/pics/2021022309321229-20230310123027977.png)
288288

289289
取栈顶元素,将栈顶元素弹出,这个就是凹槽的底部,也就是中间位置,下标记为mid,对应的高度为height[mid](就是图中的高度1)。
290290

problems/0045.跳跃游戏II.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
如图:
4949

50-
![45.跳跃游戏II](https://code-thinking-1253855093.file.myqcloud.com/pics/20201201232309103.png)
50+
![45.跳跃游戏II](https://file.kamacoder.com/pics/20201201232309103.png)
5151

5252
**图中覆盖范围的意义在于,只要红色的区域,最多两步一定可以到!(不用管具体怎么跳,反正一定可以跳到)**
5353

@@ -99,11 +99,11 @@ public:
9999
因为当移动下标指向 nums.size - 2 时:
100100
101101
- 如果移动下标等于当前覆盖最大距离下标, 需要再走一步(即 ans++),因为最后一步一定是可以到的终点。(题目假设总是可以到达数组的最后一个位置),如图:
102-
![45.跳跃游戏II2](https://code-thinking-1253855093.file.myqcloud.com/pics/20201201232445286.png)
102+
![45.跳跃游戏II2](https://file.kamacoder.com/pics/20201201232445286.png)
103103
104104
- 如果移动下标不等于当前覆盖最大距离下标,说明当前覆盖最远距离就可以直接达到终点了,不需要再走一步。如图:
105105
106-
![45.跳跃游戏II1](https://code-thinking-1253855093.file.myqcloud.com/pics/20201201232338693.png)
106+
![45.跳跃游戏II1](https://file.kamacoder.com/pics/20201201232338693.png)
107107
108108
代码如下:
109109

problems/0046.全排列.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
我以[1,2,3]为例,抽象成树形结构如下:
4242

4343

44-
![全排列](https://code-thinking-1253855093.file.myqcloud.com/pics/20240803180318.png)
44+
![全排列](https://file.kamacoder.com/pics/20240803180318.png)
4545

4646
### 回溯三部曲
4747

@@ -53,7 +53,7 @@
5353

5454
但排列问题需要一个used数组,标记已经选择的元素,如图橘黄色部分所示:
5555

56-
![全排列](https://code-thinking-1253855093.file.myqcloud.com/pics/20240803180318.png)
56+
![全排列](https://file.kamacoder.com/pics/20240803180318.png)
5757

5858
代码如下:
5959

@@ -65,7 +65,7 @@ void backtracking (vector<int>& nums, vector<bool>& used)
6565
6666
* 递归终止条件
6767
68-
![全排列](https://code-thinking-1253855093.file.myqcloud.com/pics/20240803180318.png)
68+
![全排列](https://file.kamacoder.com/pics/20240803180318.png)
6969
7070
可以看出叶子节点,就是收割结果的地方。
7171

problems/0047.全排列II.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
我以示例中的 [1,1,2]为例 (为了方便举例,已经排序)抽象为一棵树,去重过程如图:
5050

51-
![47.全排列II1](https://code-thinking-1253855093.file.myqcloud.com/pics/20201124201331223.png)
51+
![47.全排列II1](https://file.kamacoder.com/pics/20201124201331223.png)
5252

5353
图中我们对同一树层,前一位(也就是nums[i-1])如果使用过,那么就进行去重。
5454

@@ -130,11 +130,11 @@ if (i > 0 && nums[i] == nums[i - 1] && used[i - 1] == true) {
130130

131131
树层上去重(used[i - 1] == false),的树形结构如下:
132132

133-
![47.全排列II2](https://code-thinking-1253855093.file.myqcloud.com/pics/20201124201406192.png)
133+
![47.全排列II2](https://file.kamacoder.com/pics/20201124201406192.png)
134134

135135
树枝上去重(used[i - 1] == true)的树型结构如下:
136136

137-
![47.全排列II3](https://code-thinking-1253855093.file.myqcloud.com/pics/20201124201431571.png)
137+
![47.全排列II3](https://file.kamacoder.com/pics/20201124201431571.png)
138138

139139
大家应该很清晰的看到,树层上对前一位去重非常彻底,效率很高,树枝上对前一位去重虽然最后可以得到答案,但是做了很多无用搜索。
140140

0 commit comments

Comments
 (0)