> lists = new ArrayList<>();
@@ -291,7 +289,7 @@ class Solution {
}
```
-Python:
+## Python
```python
# 版本一
class Solution:
@@ -341,8 +339,9 @@ class Solution:
backtrack(s, 0)
return res
```
-Go:
-> 注意切片(go切片是披着值类型外衣的引用类型)
+## Go
+
+注意切片(go切片是披着值类型外衣的引用类型)
```go
func partition(s string) [][]string {
@@ -387,7 +386,7 @@ func isPartition(s string,startIndex,end int)bool{
}
```
-javaScript:
+## javaScript
```js
/**
diff --git a/problems/0583.两个字符串的删除操作.md b/problems/0583.两个字符串的删除操作.md
index 91b07ca9..079b2028 100644
--- a/problems/0583.两个字符串的删除操作.md
+++ b/problems/0583.两个字符串的删除操作.md
@@ -52,7 +52,7 @@ dp[i][j]:以i-1为结尾的字符串word1,和以j-1位结尾的字符串word
从递推公式中,可以看出来,dp[i][0] 和 dp[0][j]是一定要初始化的。
-dp[i][0]:word2为空字符串,以i-1为结尾的字符串word2要删除多少个元素,才能和word1相同呢,很明显dp[i][0] = i。
+dp[i][0]:word2为空字符串,以i-1为结尾的字符串word1要删除多少个元素,才能和word2相同呢,很明显dp[i][0] = i。
dp[0][j]的话同理,所以代码如下:
diff --git a/problems/知识星球精选/HR面注意事项.md b/problems/知识星球精选/HR面注意事项.md
index c6e7c194..6a0a26f1 100644
--- a/problems/知识星球精选/HR面注意事项.md
+++ b/problems/知识星球精选/HR面注意事项.md
@@ -1,9 +1,9 @@
-
-
-
+
+
+
# HR面注意事项
[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里已经有一些录友开始准备HR面。
diff --git a/problems/知识星球精选/不一样的七夕.md b/problems/知识星球精选/不一样的七夕.md
index 37e1c2da..a670e078 100644
--- a/problems/知识星球精选/不一样的七夕.md
+++ b/problems/知识星球精选/不一样的七夕.md
@@ -1,3 +1,7 @@
+
+
+
+
# 特殊的七夕
diff --git a/problems/知识星球精选/不少录友想放弃秋招.md b/problems/知识星球精选/不少录友想放弃秋招.md
index 4807dd97..721a9313 100644
--- a/problems/知识星球精选/不少录友想放弃秋招.md
+++ b/problems/知识星球精选/不少录友想放弃秋招.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 不少录友想放弃秋招了.....
马上就要九月份了,互联网大厂的秋招的序幕早已拉开。
diff --git a/problems/知识星球精选/专业技能可以这么写.md b/problems/知识星球精选/专业技能可以这么写.md
index 51522b9f..dd616713 100644
--- a/problems/知识星球精选/专业技能可以这么写.md
+++ b/problems/知识星球精选/专业技能可以这么写.md
@@ -1,3 +1,10 @@
+
+
+
+
+
+
+
# 你简历里的「专业技能」写的够专业么?
diff --git a/problems/知识星球精选/关于实习大家的疑问.md b/problems/知识星球精选/关于实习大家的疑问.md
index 118d8bf1..5d4e695b 100644
--- a/problems/知识星球精选/关于实习大家的疑问.md
+++ b/problems/知识星球精选/关于实习大家的疑问.md
@@ -1,3 +1,7 @@
+
+
+
+
# 关于实习,大家可能有点迷茫!
diff --git a/problems/知识星球精选/关于提前批的一些建议.md b/problems/知识星球精选/关于提前批的一些建议.md
index fcf41a7e..415a8b2f 100644
--- a/problems/知识星球精选/关于提前批的一些建议.md
+++ b/problems/知识星球精选/关于提前批的一些建议.md
@@ -1,3 +1,7 @@
+
+
+
+
# 秋招和提前批都越来越提前了....
diff --git a/problems/知识星球精选/写简历的一些问题.md b/problems/知识星球精选/写简历的一些问题.md
index 513f86ba..af42cea1 100644
--- a/problems/知识星球精选/写简历的一些问题.md
+++ b/problems/知识星球精选/写简历的一些问题.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 程序员应该这么写简历!
自运营[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)以来,我已经给星球里的录友们看了 一百多份简历,并准对大家简历上的问题都给出了对应的详细建议。
diff --git a/problems/知识星球精选/刷力扣用不用库函数.md b/problems/知识星球精选/刷力扣用不用库函数.md
index 1a613b8d..07db8564 100644
--- a/problems/知识星球精选/刷力扣用不用库函数.md
+++ b/problems/知识星球精选/刷力扣用不用库函数.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 究竟什么时候用库函数,什么时候要自己实现
在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里有录友问我,刷题究竟要不要用库函数? 刷题的时候总是禁不住库函数的诱惑,如果都不用库函数一些题目做起来还很麻烦。
diff --git a/problems/知识星球精选/刷题攻略要刷两遍.md b/problems/知识星球精选/刷题攻略要刷两遍.md
index 53907ee8..1f4fd7f9 100644
--- a/problems/知识星球精选/刷题攻略要刷两遍.md
+++ b/problems/知识星球精选/刷题攻略要刷两遍.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 代码随想录上的题目最好刷两遍以上
今天秋招可能要提前很多,往年9月份开始秋招,今天可能9月份就已经结束了,所以 正在准备秋招的录友,还是要抓紧时间了。。
diff --git a/problems/知识星球精选/博士转行计算机.md b/problems/知识星球精选/博士转行计算机.md
index cb73804e..66769264 100644
--- a/problems/知识星球精选/博士转行计算机.md
+++ b/problems/知识星球精选/博士转行计算机.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 本硕非计算机博士,如果找计算机相关工作
在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里,有一位博士录友,本硕都不是计算机,博士转的计算机,问了这样一个问题
diff --git a/problems/知识星球精选/合适自己的就是最好的.md b/problems/知识星球精选/合适自己的就是最好的.md
index 82ab8896..fda51afa 100644
--- a/problems/知识星球精选/合适自己的就是最好的.md
+++ b/problems/知识星球精选/合适自己的就是最好的.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 合适自己的,才是最好的!
秋招已经进入下半场了,不少同学也拿到了offer,但不是说非要进大厂,每个人情况都不一样,**合适自己的,就是最好的!**。
diff --git a/problems/知识星球精选/备战2022届秋招.md b/problems/知识星球精选/备战2022届秋招.md
index 383f5742..207a5e2a 100644
--- a/problems/知识星球精选/备战2022届秋招.md
+++ b/problems/知识星球精选/备战2022届秋招.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 要开始准备2022届的秋招了
在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里准备秋招的录友还真不少,也会回答过不少关于秋招的问题。
diff --git a/problems/知识星球精选/大厂新人培养体系.md b/problems/知识星球精选/大厂新人培养体系.md
index 165406f8..ccd2f1c2 100644
--- a/problems/知识星球精选/大厂新人培养体系.md
+++ b/problems/知识星球精选/大厂新人培养体系.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 大厂的新人培养体系是什么样的
之前我一直在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)和大家讲,能进大厂一定要进大厂,大厂有比较好的培养体系。
diff --git a/problems/知识星球精选/如何权衡实习与秋招复习.md b/problems/知识星球精选/如何权衡实习与秋招复习.md
index ee2fbd24..275588df 100644
--- a/problems/知识星球精选/如何权衡实习与秋招复习.md
+++ b/problems/知识星球精选/如何权衡实习与秋招复习.md
@@ -1,3 +1,7 @@
+
+
+
+
# 已经在实习的录友如何准备秋招?
diff --git a/problems/知识星球精选/客三消.md b/problems/知识星球精选/客三消.md
index 869d39de..8a7b5fc6 100644
--- a/problems/知识星球精选/客三消.md
+++ b/problems/知识星球精选/客三消.md
@@ -1,3 +1,7 @@
+
+
+
+
# 客三消!
diff --git a/problems/知识星球精选/技术不好如何选择技术方向.md b/problems/知识星球精选/技术不好如何选择技术方向.md
index ad8a777c..dd13f46b 100644
--- a/problems/知识星球精选/技术不好如何选择技术方向.md
+++ b/problems/知识星球精选/技术不好如何选择技术方向.md
@@ -1,3 +1,7 @@
+
+
+
+
# 技术不太好,也不知道对技术有没有兴趣,我该怎么选?
diff --git a/problems/知识星球精选/提前批已经开始了.md b/problems/知识星球精选/提前批已经开始了.md
index ec8ede8e..ba05b5a9 100644
--- a/problems/知识星球精选/提前批已经开始了.md
+++ b/problems/知识星球精选/提前批已经开始了.md
@@ -1,3 +1,9 @@
+
+
+
+
+
+# 不知不觉华为提前提已经开始了
最近华为提前批已经开始了,不少同学已经陆续参加了提前批的面试。
diff --git a/problems/知识星球精选/秋招下半场依然没offer.md b/problems/知识星球精选/秋招下半场依然没offer.md
index 9800452c..829f82ba 100644
--- a/problems/知识星球精选/秋招下半场依然没offer.md
+++ b/problems/知识星球精选/秋招下半场依然没offer.md
@@ -1,3 +1,7 @@
+
+
+
+
# 秋招下半场依然没offer,怎么办?
diff --git a/problems/知识星球精选/秋招的上半场.md b/problems/知识星球精选/秋招的上半场.md
index 8ba938ea..f404e611 100644
--- a/problems/知识星球精选/秋招的上半场.md
+++ b/problems/知识星球精选/秋招的上半场.md
@@ -1,3 +1,7 @@
+
+
+
+
# 秋招上半场的总结
diff --git a/problems/知识星球精选/秋招进行中的迷茫与焦虑.md b/problems/知识星球精选/秋招进行中的迷茫与焦虑.md
index bdd59d4f..6083c7b1 100644
--- a/problems/知识星球精选/秋招进行中的迷茫与焦虑.md
+++ b/problems/知识星球精选/秋招进行中的迷茫与焦虑.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 秋招进行时,其实大家都很焦虑
大家应该都发现了,提前批和秋招都越来越提前的,大部分的录友此时的心态还是挺焦虑的。
diff --git a/problems/知识星球精选/英语到底重不重要.md b/problems/知识星球精选/英语到底重不重要.md
index d1f647c0..32e6a39b 100644
--- a/problems/知识星球精选/英语到底重不重要.md
+++ b/problems/知识星球精选/英语到底重不重要.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 对程序员来说,英语到底重不重要
在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)有一位录友问了我这么一个问题。
diff --git a/problems/知识星球精选/要不要考研.md b/problems/知识星球精选/要不要考研.md
index d67b95b7..a5f2dfa0 100644
--- a/problems/知识星球精选/要不要考研.md
+++ b/problems/知识星球精选/要不要考研.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 到底要不要读研
在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里讨论了一下关于要不要读研的问题。
diff --git a/problems/知识星球精选/面试中发散性问题.md b/problems/知识星球精选/面试中发散性问题.md
index 550b51d2..7fb9150f 100644
--- a/problems/知识星球精选/面试中发散性问题.md
+++ b/problems/知识星球精选/面试中发散性问题.md
@@ -1,3 +1,8 @@
+
+
+
+
+
# 面试中遇到发散性问题,应该怎么办?
这周在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)有一位录友问了我这么一个问题,我感觉挺有代表性的,应该不少录友在面试中不论是社招还是校招都会遇到这一类的问题。
diff --git a/problems/背包理论基础01背包-1.md b/problems/背包理论基础01背包-1.md
index 32ad30d3..030c00d2 100644
--- a/problems/背包理论基础01背包-1.md
+++ b/problems/背包理论基础01背包-1.md
@@ -123,7 +123,7 @@ for (int j = weight[0]; j <= bagWeight; j++) {
dp[0][j] 和 dp[i][0] 都已经初始化了,那么其他下标应该初始化多少呢?
-其实从递归公式: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]); 可以看出dp[i][j] 是又左上方数值推导出来了,那么 其他下标初始为什么数值都可以,因为都会被覆盖。
+其实从递归公式: dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]); 可以看出dp[i][j] 是由左上方数值推导出来了,那么 其他下标初始为什么数值都可以,因为都会被覆盖。
**初始-1,初始-2,初始100,都可以!**
From f7990b703ba835e0e624f8ad3d2bbad14a552b0e Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 12:39:55 +0800
Subject: [PATCH 135/284] =?UTF-8?q?649.Dota2=E5=8F=82=E8=AE=AE=E9=99=A2=20?=
=?UTF-8?q?=E6=96=B0=E5=A2=9EJavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0649.Dota2参议院.md | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/problems/0649.Dota2参议院.md b/problems/0649.Dota2参议院.md
index e2900824..cda5dd95 100644
--- a/problems/0649.Dota2参议院.md
+++ b/problems/0649.Dota2参议院.md
@@ -219,6 +219,31 @@ func predictPartyVictory(senateStr string) string {
## JavaScript
```js
+var predictPartyVictory = function(senateStr) {
+ // R = true表示本轮循环结束后,字符串里依然有R;D同理。
+ let R = true, D = true;
+ // 当flag大于0时,R在D前出现,R可以消灭D。当flag小于0时,D在R前出现,D可以消灭R
+ let flag = 0;
+ let senate = senateStr.split('');
+ while(R && D){ // 一旦R或者D为false,就结束循环,说明本轮结束后只剩下R或者D了
+ R = false;
+ D = false;
+ for(let i = 0; i < senate.length; i++){
+ if(senate[i] === 'R'){
+ if(flag < 0) senate[i] = 0;// 消灭R,R此时为false
+ else R = true;// 如果没被消灭,本轮循环结束有R
+ flag++;
+ }
+ if(senate[i] === 'D'){
+ if(flag > 0) senate[i] = 0;
+ else D = true;
+ flag--;
+ }
+ }
+ }
+ // 循环结束之后,R和D只能有一个为true
+ return R ? "Radiant" : "Dire";
+};
```
-----------------------
From 55e185b5e651860f0363cea4a5fdfdbe72ba1310 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 13:06:39 +0800
Subject: [PATCH 136/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201207.=E7=8B=AC?=
=?UTF-8?q?=E4=B8=80=E6=97=A0=E4=BA=8C=E7=9A=84=E5=87=BA=E7=8E=B0=E6=AC=A1?=
=?UTF-8?q?=E6=95=B0=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1207.独一无二的出现次数.md | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md
index 027c9f5a..f18af16c 100644
--- a/problems/1207.独一无二的出现次数.md
+++ b/problems/1207.独一无二的出现次数.md
@@ -118,7 +118,23 @@ class Solution:
Go:
JavaScript:
-
+``` javascript
+var uniqueOccurrences = function(arr) {
+ const count = new Array(2002).fill(0);// -1000 <= arr[i] <= 1000
+ for(let i = 0; i < arr.length; i++){
+ count[arr[i] + 1000]++;// 防止负数作为下标
+ }
+ // 标记相同频率是否重复出现
+ const fre = new Array(1002).fill(false);// 1 <= arr.length <= 1000
+ for(let i = 0; i <= 2000; i++){
+ if(count[i] > 0){//有i出现过
+ if(fre[count[i]] === false) fre[count[i]] = true;//之前未出现过,标记为出现
+ else return false;//之前就出现了,重复出现
+ }
+ }
+ return true;
+};
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From 24c515282ada19201d460a7e27ddc4979c3eb7ee Mon Sep 17 00:00:00 2001
From: yqq
Date: Mon, 27 Sep 2021 16:08:33 +0800
Subject: [PATCH 137/284] =?UTF-8?q?1002.=20=E6=9F=A5=E6=89=BE=E5=B8=B8?=
=?UTF-8?q?=E7=94=A8=E5=AD=97=E7=AC=A6,=20=20=20=E6=9B=B4=E6=96=B0?=
=?UTF-8?q?=E9=A2=98=E7=9B=AE=E6=8F=8F=E8=BF=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1002.查找常用字符.md | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md
index e02780da..043d20a4 100644
--- a/problems/1002.查找常用字符.md
+++ b/problems/1002.查找常用字符.md
@@ -12,18 +12,24 @@
[力扣题目链接](https://leetcode-cn.com/problems/find-common-characters/)
-给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。
+给你一个字符串数组 words ,请你找出所有在 words 的每个字符串中都出现的共用字符( 包括重复字符),并以数组形式返回。你可以按 任意顺序 返回答案。
-你可以按任意顺序返回答案。
+示例 1:
-【示例一】
-输入:["bella","label","roller"]
+输入:words = ["bella","label","roller"]
输出:["e","l","l"]
+示例 2:
-【示例二】
-输入:["cool","lock","cook"]
+输入:words = ["cool","lock","cook"]
输出:["c","o"]
+提示:
+
+1 <= words.length <= 100
+1 <= words[i].length <= 100
+words[i] 由小写英文字母组成
+
+
# 思路
From ff3f31aed05dd05c5740b63415f494b198c8a477 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 16:14:35 +0800
Subject: [PATCH 138/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20283.=20=E7=A7=BB?=
=?UTF-8?q?=E5=8A=A8=E9=9B=B6=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0283.移动零.md | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/problems/0283.移动零.md b/problems/0283.移动零.md
index 3909bcd5..2498bdc3 100644
--- a/problems/0283.移动零.md
+++ b/problems/0283.移动零.md
@@ -95,6 +95,21 @@ Python:
Go:
JavaScript:
+```javascript
+var moveZeroes = function(nums) {
+ let slow = 0;
+ for(let fast = 0; fast < nums.length; fast++){
+ if(nums[fast] != 0){//找到非0的元素
+ nums[slow] = nums[fast];//把非0的元素赋值给数组慢指针指向的索引处的值
+ slow++;//慢指针向右移动
+ }
+ }
+ // 后面的元素全变成 0
+ for(let j = slow; j < nums.length; j++){
+ nums[j] = 0;
+ }
+};
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
From a1e32680ac4e314969dbf7578caac5b7e80b3aa2 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 16:40:41 +0800
Subject: [PATCH 139/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20463.=E5=B2=9B?=
=?UTF-8?q?=E5=B1=BF=E7=9A=84=E5=91=A8=E9=95=BF=20JavaScript=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0463.岛屿的周长.md | 49 +++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/problems/0463.岛屿的周长.md b/problems/0463.岛屿的周长.md
index fd9585d2..e6077456 100644
--- a/problems/0463.岛屿的周长.md
+++ b/problems/0463.岛屿的周长.md
@@ -120,6 +120,55 @@ Python:
Go:
JavaScript:
+```javascript
+//解法一
+var islandPerimeter = function(grid) {
+ // 上下左右 4 个方向
+ const dirx = [-1, 1, 0, 0], diry = [0, 0, -1, 1];
+ const m = grid.length, n = grid[0].length;
+ let res = 0; //岛屿周长
+ for(let i = 0; i < m; i++){
+ for(let j = 0; j < n; j++){
+ if(grid[i][j] === 1){
+ for(let k = 0; k < 4; k++){ //上下左右四个方向
+ // 计算周边坐标的x,y
+ let x = i + dirx[k];
+ let y = j + diry[k];
+ // 四个方向扩展的新位置是水域或者越界就会为周长贡献1
+ if(x < 0 // i在边界上
+ || x >= m // i在边界上
+ || y < 0 // j在边界上
+ || y >= n // j在边界上
+ || grid[x][y] === 0){ // (x,y)位置是水域
+ res++;
+ continue;
+ }
+ }
+ }
+ }
+ }
+ return res;
+};
+
+//解法二
+var islandPerimeter = function(grid) {
+ let sum = 0; // 陆地数量
+ let cover = 0; // 相邻数量
+ for(let i = 0; i < grid.length; i++){
+ for(let j = 0; j = 0 && grid[i-1][j] === 1) cover++;
+ // 统计左边相邻陆地
+ if(j - 1 >= 0 && grid[i][j-1] === 1) cover++;
+ // 为什么没统计下边和右边? 因为避免重复计算
+ }
+ }
+ }
+ return sum * 4 - cover * 2;
+};
+```
-----------------------
From 195b8aefddc4266487c2c0894344134d4594bdb0 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 17:23:26 +0800
Subject: [PATCH 140/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E1221.=E5=88=86?=
=?UTF-8?q?=E5=89=B2=E5=B9=B3=E8=A1=A1=E5=AD=97=E7=AC=A6=E4=B8=B2=20JavaSc?=
=?UTF-8?q?ript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1221.分割平衡字符串.md | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/problems/1221.分割平衡字符串.md b/problems/1221.分割平衡字符串.md
index c764e3ff..381ad060 100644
--- a/problems/1221.分割平衡字符串.md
+++ b/problems/1221.分割平衡字符串.md
@@ -108,6 +108,15 @@ public:
## JavaScript
```js
+var balancedStringSplit = function(s) {
+ let res = 0, total = 0;//res为平衡字符串数量 total为当前"R"字符和"L"字符的数量差
+ for(let c of s){// 遍历字符串每个字符
+ //因为开始字符数量差就是0,遍历的时候要先改变数量差,否则会影响结果数量
+ total += c === 'R' ? 1:-1;//遇到"R",total++;遇到"L",total--
+ if(total === 0) res++;//只要"R""L"数量一样就可以算是一个平衡字符串
+ }
+ return res;
+};
```
-----------------------
From 571ce5788e816d59fe6266e95a5eeeba36e965df Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 17:44:58 +0800
Subject: [PATCH 141/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A01356.=20=E5=A6=82?=
=?UTF-8?q?=E4=BD=95=E8=AE=A1=E7=AE=97=E4=BA=8C=E8=BF=9B=E5=88=B6=E4=B8=AD?=
=?UTF-8?q?1=E7=9A=84=E6=95=B0=E9=87=8F=20JavaScript=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1356.根据数字二进制下1的数目排序.md | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/problems/1356.根据数字二进制下1的数目排序.md b/problems/1356.根据数字二进制下1的数目排序.md
index 06c29500..c7e856d1 100644
--- a/problems/1356.根据数字二进制下1的数目排序.md
+++ b/problems/1356.根据数字二进制下1的数目排序.md
@@ -166,6 +166,18 @@ class Solution {
## JavaScript
```js
+var sortByBits = function(arr) {
+ const bitCount = n =>{// 计算n的二进制中1的数量
+ let count = 0;
+ while(n){
+ n &= (n - 1);// 清除最低位的1
+ count++;
+ }
+ return count;
+ }
+ // 如果有差,则按bits数排,如果无差,则按原值排
+ return arr.sort((a,b) => bitCount(a) - bitCount(b) || a - b);
+};
```
-----------------------
From 16dcd4cd839c17d4417801c6ee1dc59c84aa4c29 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 17:54:30 +0800
Subject: [PATCH 142/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A01365.=20=E6=9C=89?=
=?UTF-8?q?=E5=A4=9A=E5=B0=91=E5=B0=8F=E4=BA=8E=E5=BD=93=E5=89=8D=E6=95=B0?=
=?UTF-8?q?=E5=AD=97=E7=9A=84=E6=95=B0=E5=AD=97=20JavaScript=E8=A7=A3?=
=?UTF-8?q?=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1365.有多少小于当前数字的数字.md | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/problems/1365.有多少小于当前数字的数字.md b/problems/1365.有多少小于当前数字的数字.md
index 5cf6b2d8..cd003f2f 100644
--- a/problems/1365.有多少小于当前数字的数字.md
+++ b/problems/1365.有多少小于当前数字的数字.md
@@ -155,7 +155,23 @@ class Solution:
Go:
JavaScript:
-
+```javascript
+var smallerNumbersThanCurrent = function(nums) {
+ const map = new Map();// 记录数字 nums[i] 有多少个比它小的数字
+ const res = nums.slice(0);//深拷贝nums
+ res.sort((a,b) => a - b);
+ for(let i = 0; i < res.length; i++){
+ if(!map.has(res[i])){// 遇到了相同的数字,那么不需要更新该 number 的情况
+ map.set(res[i],i);
+ }
+ }
+ // 此时map里保存的每一个元素数值 对应的 小于这个数值的个数
+ for(let i = 0; i < nums.length; i++){
+ res[i] = map.get(nums[i]);
+ }
+ return res;
+};
+```
-----------------------
From a5a088b35fe494205d61479a267205df4692f7cd Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 18:14:07 +0800
Subject: [PATCH 143/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A01382.=20=E5=B0=86?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91=E5=8F=98=E5=B9=B3?=
=?UTF-8?q?=E8=A1=A1=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1382.将二叉搜索树变平衡.md | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/problems/1382.将二叉搜索树变平衡.md b/problems/1382.将二叉搜索树变平衡.md
index bce58c33..8e1cbe37 100644
--- a/problems/1382.将二叉搜索树变平衡.md
+++ b/problems/1382.将二叉搜索树变平衡.md
@@ -126,6 +126,29 @@ class Solution:
Go:
JavaScript:
+```javascript
+var balanceBST = function(root) {
+ const res = [];
+ // 中序遍历转成有序数组
+ const travesal = cur => {
+ if(!cur) return;
+ travesal(cur.left);
+ res.push(cur.val);
+ travesal(cur.right);
+ }
+ // 有序数组转成平衡二叉树
+ const getTree = (nums, left, right) => {
+ if(left > right) return null;
+ let mid = left + ((right - left) >> 1);
+ let root = new TreeNode(nums[mid]);// 中心位置作为当前节点的值
+ root.left = getTree(nums, left, mid - 1);// 递归地将区间[left,mid−1] 作为当前节点的左子树
+ root.right = getTree(nums, mid + 1, right);// 递归地将区间[mid+1,right] 作为当前节点的左子树
+ return root;
+ }
+ travesal(root);
+ return getTree(res, 0, res.length - 1);
+};
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
From 03582efc4a2e8532d48e70e9bbfad78de430ed65 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 18:23:48 +0800
Subject: [PATCH 144/284] =?UTF-8?q?Update=200941.=E6=9C=89=E6=95=88?=
=?UTF-8?q?=E7=9A=84=E5=B1=B1=E8=84=89=E6=95=B0=E7=BB=84.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0941.有效的山脉数组.md | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/problems/0941.有效的山脉数组.md b/problems/0941.有效的山脉数组.md
index c4c8ebfa..2073ba59 100644
--- a/problems/0941.有效的山脉数组.md
+++ b/problems/0941.有效的山脉数组.md
@@ -154,6 +154,16 @@ func validMountainArray(arr []int) bool {
## JavaScript
```js
+var validMountainArray = function(arr) {
+ if(arr.length < 3) return false;// 一定不是山脉数组
+ let left = 0, right = arr.length - 1;// 双指针
+ // 注意防止越界
+ while(left < arr.length && arr[left] < arr[left+1]) left++;
+ while(right>0 && arr[right-1] > arr[right]) right--;
+ // 如果left或者right都在起始位置,说明不是山峰
+ if(left === right && left !== 0 && right !== arr.length - 1) return true;
+ return false;
+};
```
-----------------------
From db571bd895e46dce7fb7b4d707dd71719e795060 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 18:35:36 +0800
Subject: [PATCH 145/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0925.=E9=95=BF?=
=?UTF-8?q?=E9=94=AE=E6=8C=89=E5=85=A5=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0925.长按键入.md | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/problems/0925.长按键入.md b/problems/0925.长按键入.md
index 70597508..02dca305 100644
--- a/problems/0925.长按键入.md
+++ b/problems/0925.长按键入.md
@@ -182,6 +182,34 @@ func isLongPressedName(name string, typed string) bool {
```
JavaScript:
+```javascript
+var isLongPressedName = function(name, typed) {
+ let i = 0, j = 0;
+ const m = name.length, n = typed.length;
+ while(i < m && j < n){
+ if(name[i] === typed[j]){ // 相同则同时向后匹配
+ i++; j++;
+ } else {
+ if(j === 0) return false; // 如果是第一位就不相同直接返回false
+ // 判断边界为n-1,若为n会越界,例如name:"kikcxmvzi" typed:"kiikcxxmmvvzzz"
+ while(j < n - 1 && typed[j] === typed[j-1]) j++;
+ if(name[i] === typed[j]){ // j跨越重复项之后再次和name[i]匹配,相同则同时向后匹配
+ i++; j++;
+ } else {
+ return false;
+ }
+ }
+ }
+ // 说明name没有匹配完 例如 name:"pyplrzzzzdsfa" type:"ppyypllr"
+ if(i < m) return false;
+ // 说明type没有匹配完 例如 name:"alex" type:"alexxrrrrssda"
+ while(j < n) {
+ if(typed[j] === typed[j-1]) j++;
+ else return false;
+ }
+ return true;
+};
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
From a35adcffbee7ff9c229cff38eff9506b396c0186 Mon Sep 17 00:00:00 2001
From: yqq
Date: Mon, 27 Sep 2021 18:51:54 +0800
Subject: [PATCH 146/284] =?UTF-8?q?1035.=E4=B8=8D=E7=9B=B8=E4=BA=A4?=
=?UTF-8?q?=E7=9A=84=E7=BA=BF.md,=20=E5=A2=9E=E5=8A=A0Golang=E5=AE=9E?=
=?UTF-8?q?=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1035.不相交的线.md | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md
index a10fd381..8795a77d 100644
--- a/problems/1035.不相交的线.md
+++ b/problems/1035.不相交的线.md
@@ -109,6 +109,41 @@ class Solution:
return dp[-1][-1]
```
+
+Golang:
+
+```go
+
+func maxUncrossedLines(A []int, B []int) int {
+ m, n := len(A), len(B)
+ dp := make([][]int, m+1)
+ for i := range dp {
+ dp[i] = make([]int, n+1)
+ }
+
+ for i := 1; i <= len(A); i++ {
+ for j := 1; j <= len(B); j++ {
+ if (A[i - 1] == B[j - 1]) {
+ dp[i][j] = dp[i - 1][j - 1] + 1;
+ } else {
+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
+ }
+ }
+ }
+ return dp[m][n];
+
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+```
+
+
+
JavaScript:
```javascript
From a3b5912c1aee1096e7e7cf2c2d9dfd1df0d6a5cc Mon Sep 17 00:00:00 2001
From: yqq
Date: Mon, 27 Sep 2021 18:52:44 +0800
Subject: [PATCH 147/284] fix
---
problems/1035.不相交的线.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md
index 8795a77d..22cf613b 100644
--- a/problems/1035.不相交的线.md
+++ b/problems/1035.不相交的线.md
@@ -124,13 +124,13 @@ func maxUncrossedLines(A []int, B []int) int {
for i := 1; i <= len(A); i++ {
for j := 1; j <= len(B); j++ {
if (A[i - 1] == B[j - 1]) {
- dp[i][j] = dp[i - 1][j - 1] + 1;
+ dp[i][j] = dp[i - 1][j - 1] + 1
} else {
- dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
}
}
}
- return dp[m][n];
+ return dp[m][n]
}
From 224dc5f5612fb916bb6e97fd1026d2bc2c49bd30 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 18:54:45 +0800
Subject: [PATCH 148/284] =?UTF-8?q?Update=200922.=E6=8C=89=E5=A5=87?=
=?UTF-8?q?=E5=81=B6=E6=8E=92=E5=BA=8F=E6=95=B0=E7=BB=84II.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0922.按奇偶排序数组II.md | 51 +++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/problems/0922.按奇偶排序数组II.md b/problems/0922.按奇偶排序数组II.md
index 5b66247e..05cff32a 100644
--- a/problems/0922.按奇偶排序数组II.md
+++ b/problems/0922.按奇偶排序数组II.md
@@ -209,6 +209,57 @@ func sortArrayByParityII(nums []int) []int {
## JavaScript
```js
+//方法一
+var sortArrayByParityII = function(nums) {
+ const n = nums.length;
+ // 分别存放 nums 中的奇数、偶数
+ let evenIndex = 0, oddIndex = 0;
+ // 初始化就确定数组大小,节省开销
+ const even = new Array(Math.floor(n/2));
+ const odd = new Array(Math.floor(n/2));
+ // 把A数组放进偶数数组,和奇数数组
+ for(let i = 0; i < n; i++){
+ if(nums[i] % 2 === 0) even[evenIndex++] = nums[i];
+ else odd[oddIndex++] = nums[i];
+ }
+ // 把奇偶数组重新存回 nums
+ let index = 0;
+ for(let i = 0; i < even.length; i++){
+ nums[index++] = even[i];
+ nums[index++] = odd[i];
+ }
+ return nums;
+};
+
+//方法二
+var sortArrayByParityII = function(nums) {
+ const n = nums.length;
+ const result = new Array(n);
+ // 偶数下标 和 奇数下标
+ let evenIndex = 0, oddIndex = 1;
+ for(let i = 0; i < n; i++){
+ if(nums[i] % 2 === 0) {
+ result[evenIndex] = nums[i];
+ evenIndex += 2;
+ } else {
+ result[oddIndex] = nums[i];
+ oddIndex += 2;
+ }
+ }
+ return result;
+};
+
+//方法三
+var sortArrayByParityII = function(nums) {
+ let oddIndex = 1;
+ for(let i = 0; i < nums.length; i += 2){
+ if(nums[i] % 2 === 1){ // 在偶数位遇到了奇数
+ while(nums[oddIndex] % 2 !== 0) oddIndex += 2;// 在奇数位找一个偶数
+ [nums[oddIndex], nums[i]] = [nums[i], nums[oddIndex]]; // 解构赋值交换
+ }
+ }
+ return nums;
+};
```
-----------------------
From 8edca00e487878a00b16a296b35ff9a14fb3cb2f Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 20:37:23 +0800
Subject: [PATCH 149/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E724.=20=E5=AF=BB?=
=?UTF-8?q?=E6=89=BE=E6=95=B0=E7=BB=84=E7=9A=84=E4=B8=AD=E5=BF=83=E7=B4=A2?=
=?UTF-8?q?=E5=BC=95=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0724.寻找数组的中心索引.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/problems/0724.寻找数组的中心索引.md b/problems/0724.寻找数组的中心索引.md
index 991ce647..d5fa48ee 100644
--- a/problems/0724.寻找数组的中心索引.md
+++ b/problems/0724.寻找数组的中心索引.md
@@ -129,6 +129,17 @@ func pivotIndex(nums []int) int {
## JavaScript
```js
+var pivotIndex = function(nums) {
+ const sum = nums.reduce((a,b) => a + b);//求和
+ // 中心索引左半和 中心索引右半和
+ let leftSum = 0, rightSum = 0;
+ for(let i = 0; i < nums.length; i++){
+ leftSum += nums[i];
+ rightSum = sum - leftSum + nums[i];// leftSum 里面已经有 nums[i],多减了一次,所以加上
+ if(leftSum === rightSum) return i;
+ }
+ return -1;
+};
```
-----------------------
From 5a10b329da87245d11a46564af8e4cb00c122113 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 20:48:55 +0800
Subject: [PATCH 150/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0673.=20=E6=9C=80?=
=?UTF-8?q?=E9=95=BF=E9=80=92=E5=A2=9E=E5=AD=90=E5=BA=8F=E5=88=97=E7=9A=84?=
=?UTF-8?q?=E4=B8=AA=E6=95=B0=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0673.最长递增子序列的个数.md | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/problems/0673.最长递增子序列的个数.md b/problems/0673.最长递增子序列的个数.md
index 653edadf..bf0a2a5a 100644
--- a/problems/0673.最长递增子序列的个数.md
+++ b/problems/0673.最长递增子序列的个数.md
@@ -337,6 +337,28 @@ func findNumberOfLIS(nums []int) int {
## JavaScript
```js
+var findNumberOfLIS = function(nums) {
+ const len = nums.length;
+ if(len <= 1) return len;
+ let dp = new Array(len).fill(1); // i之前(包括i)最长递增子序列的长度为dp[i]
+ let count = new Array(len).fill(1); // 以nums[i]为结尾的字符串,最长递增子序列的个数为count[i]
+ let res = 0;
+ for(let i = 1; i < len; i++){
+ for(let j = 0; j < i; j++){
+ if(nums[i] > nums[j]){
+ if(dp[j] + 1 > dp[i]){ // 第 j 个数字为前一个数字的子序列是否更更长
+ dp[i] = dp[j] + 1; //更新 dp[i]
+ count[i] = count[j]; // 重置count[i]
+ } else if(dp[j] + 1 === dp[i]){ // 和原来一样长
+ count[i] += count[j]; //更新count[i]
+ }
+ }
+ }
+ }
+ let max = Math.max(...dp); //扩展运算符找到最大长度
+ for(let i = 0; i < len; i++) if(dp[i] === max) res += count[i]; // 累加
+ return res;
+};
```
-----------------------
From 93f29ed6d5cce50ccaf057a8a3177318c105b344 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 20:55:52 +0800
Subject: [PATCH 151/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20205.=20=E5=90=8C?=
=?UTF-8?q?=E6=9E=84=E5=AD=97=E7=AC=A6=E4=B8=B2=20JavaScript=E8=A7=A3?=
=?UTF-8?q?=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0205.同构字符串.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/problems/0205.同构字符串.md b/problems/0205.同构字符串.md
index 5d20aa4a..1b4d0e32 100644
--- a/problems/0205.同构字符串.md
+++ b/problems/0205.同构字符串.md
@@ -119,6 +119,25 @@ func isIsomorphic(s string, t string) bool {
## JavaScript
```js
+var isIsomorphic = function(s, t) {
+ let len = s.length;
+ if(len === 0) return true;
+ let maps = new Map();
+ let mapt = new Map();
+ for(let i = 0, j = 0; i < len; i++, j++){
+ if(!maps.has(s[i])){
+ maps.set(s[i],t[j]);// maps保存 s[i] 到 t[j]的映射
+ }
+ if(!mapt.has(t[i])){
+ mapt.set(t[j],s[i]);// mapt保存 t[j] 到 s[i]的映射
+ }
+ // 无法映射,返回 false
+ if(maps.get(s[i]) !== t[j] || mapt.get(t[j]) !== s[i]){
+ return false;
+ }
+ };
+ return true;
+};
```
-----------------------
From 6158db21aac6409775a20ffb117ab4c8a39801e7 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 20:57:26 +0800
Subject: [PATCH 152/284] =?UTF-8?q?js=E7=89=88=E6=9C=AC=E7=AC=94=E8=AF=AF?=
=?UTF-8?q?=EF=BC=8C=E7=A8=8D=E4=BD=9C=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0205.同构字符串.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0205.同构字符串.md b/problems/0205.同构字符串.md
index 1b4d0e32..478b5290 100644
--- a/problems/0205.同构字符串.md
+++ b/problems/0205.同构字符串.md
@@ -128,7 +128,7 @@ var isIsomorphic = function(s, t) {
if(!maps.has(s[i])){
maps.set(s[i],t[j]);// maps保存 s[i] 到 t[j]的映射
}
- if(!mapt.has(t[i])){
+ if(!mapt.has(t[j])){
mapt.set(t[j],s[i]);// mapt保存 t[j] 到 s[i]的映射
}
// 无法映射,返回 false
From 65901bdee41eb6071ca6c03209b114bcf562ffd4 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 21:07:45 +0800
Subject: [PATCH 153/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20234.=20=E5=9B=9E?=
=?UTF-8?q?=E6=96=87=E9=93=BE=E8=A1=A8=20JavaScript=20=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0234.回文链表.md | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/problems/0234.回文链表.md b/problems/0234.回文链表.md
index 631d2f6b..c93e534e 100644
--- a/problems/0234.回文链表.md
+++ b/problems/0234.回文链表.md
@@ -284,7 +284,41 @@ class Solution:
## JavaScript
```js
-
+var isPalindrome = function(head) {
+ const reverseList = head => {// 反转链表
+ let temp = null;
+ let pre = null;
+ while(head != null){
+ temp = head.next;
+ head.next = pre;
+ pre = head;
+ head = temp;
+ }
+ return pre;
+ }
+ // 如果为空或者仅有一个节点,返回true
+ if(!head && !head.next) return true;
+ let slow = head;
+ let fast = head;
+ let pre = head;
+ while(fast != null && fast.next != null){
+ pre = slow; // 记录slow的前一个结点
+ slow = slow.next;
+ fast = fast.next.next;
+ }
+ pre.next = null; // 分割两个链表
+ // 前半部分
+ let cur1 = head;
+ // 后半部分。这里使用了反转链表
+ let cur2 = reverseList(slow);
+ while(cur1 != null){
+ if(cur1.val != cur2.val) return false;
+ // 注意要移动两个结点
+ cur1 = cur1.next;
+ cur2 = cur2.next;
+ }
+ return true;
+};
```
From 227bed3396b3695119d5f1169fb15e4840ce50cb Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 21:12:33 +0800
Subject: [PATCH 154/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20141.=20=E7=8E=AF?=
=?UTF-8?q?=E5=BD=A2=E9=93=BE=E8=A1=A8=20JavaScript=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0141.环形链表.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/problems/0141.环形链表.md b/problems/0141.环形链表.md
index 34b8d25f..14c21b67 100644
--- a/problems/0141.环形链表.md
+++ b/problems/0141.环形链表.md
@@ -114,6 +114,17 @@ class Solution:
## JavaScript
```js
+var hasCycle = function(head) {
+ let fast = head;
+ let slow = head;
+ // 空链表、单节点链表一定不会有环
+ while(fast != null && fast.next != null){
+ fast = fast.next.next; // 快指针,一次移动两步
+ slow = slow.next; // 慢指针,一次移动一步
+ if(fast === slow) return true; // 快慢指针相遇,表明有环
+ }
+ return false; // 正常走到链表末尾,表明没有环
+};
```
-----------------------
From 66b3cac2c7e62e4ee5c4aae316611b39fac740b2 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 21:23:55 +0800
Subject: [PATCH 155/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E70.=E7=88=AC=E6=A5=BC?=
=?UTF-8?q?=E6=A2=AF=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0070.爬楼梯完全背包版本.md | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md
index 4410dbaf..097ecfdb 100644
--- a/problems/0070.爬楼梯完全背包版本.md
+++ b/problems/0070.爬楼梯完全背包版本.md
@@ -186,6 +186,20 @@ func climbStairs(n int) int {
}
```
+JavaScript:
+```javascript
+var climbStairs = function(n) {
+ const dp = new Array(n+1).fill(0);
+ const weight = [1,2];
+ dp[0] = 1;
+ for(let i = 0; i <= n; i++){ //先遍历背包
+ for(let j = 0; j < weight.length; j++){ // 再遍历物品
+ if(i >= weight[j]) dp[i] += dp[i-weight[j]];
+ }
+ }
+ return dp[n];
+};
+```
-----------------------
From f34b2472643b6ebc98b16856b90f25835294c0c1 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 21:34:56 +0800
Subject: [PATCH 156/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E34.=E6=9C=B4=E5=AE=9E?=
=?UTF-8?q?=E6=97=A0=E5=8D=8E=E7=9A=84=E4=BA=8C=E5=88=86=E6=9F=A5=E6=89=BE?=
=?UTF-8?q?=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...排序数组中查找元素的第一个和最后一个位置.md | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
index 68dd797d..33694577 100644
--- a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
+++ b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
@@ -396,6 +396,46 @@ class Solution:
## JavaScript
```js
+var searchRange = function(nums, target) {
+ const getLeftBorder = (nums, target) => {
+ let left = 0, right = nums.length - 1;
+ let leftBorder = -2;// 记录一下leftBorder没有被赋值的情况
+ while(left <= right){
+ let middle = left + ((right - left) >> 1);
+ if(nums[middle] >= target){ // 寻找左边界,nums[middle] == target的时候更新right
+ right = middle - 1;
+ leftBorder = right;
+ } else {
+ left = middle + 1;
+ }
+ }
+ return leftBorder;
+ }
+
+ const getRightBorder = (nums, target) => {
+ let left = 0, right = nums.length - 1;
+ let rightBorder = -2; // 记录一下rightBorder没有被赋值的情况
+ while (left <= right) {
+ let middle = left + ((right - left) >> 1);
+ if (nums[middle] > target) {
+ right = middle - 1;
+ } else { // 寻找右边界,nums[middle] == target的时候更新left
+ left = middle + 1;
+ rightBorder = left;
+ }
+ }
+ return rightBorder;
+ }
+
+ let leftBorder = getLeftBorder(nums, target);
+ let rightBorder = getRightBorder(nums, target);
+ // 情况一
+ if(leftBorder === -2 || rightBorder === -2) return [-1,-1];
+ // 情况三
+ if (rightBorder - leftBorder > 1) return [leftBorder + 1, rightBorder - 1];
+ // 情况二
+ return [-1, -1];
+};
```
-----------------------
From 33c2715b85f48365a7eff33ad488af98c23f169c Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 22:03:18 +0800
Subject: [PATCH 157/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E=2031.=20=E4=B8=8B?=
=?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=8E=92=E5=88=97=20JavaScript=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0031.下一个排列.md | 46 +++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/problems/0031.下一个排列.md b/problems/0031.下一个排列.md
index 05321a9a..46568fae 100644
--- a/problems/0031.下一个排列.md
+++ b/problems/0031.下一个排列.md
@@ -132,6 +132,52 @@ class Solution {
## JavaScript
```js
+//卡尔的解法(吐槽一下JavaScript的sort和其他语言的不太一样,只想到了拷贝数组去排序再替换原数组来实现nums的[i + 1, nums.length)升序排序)
+var nextPermutation = function(nums) {
+ for(let i = nums.length - 1; i >= 0; i--){
+ for(let j = nums.length - 1; j > i; j--){
+ if(nums[j] > nums[i]){
+ [nums[j],nums[i]] = [nums[i],nums[j]]; // 交换
+ // 深拷贝[i + 1, nums.length)部分到新数组arr
+ let arr = nums.slice(i+1);
+ // arr升序排序
+ arr.sort((a,b) => a - b);
+ // arr替换nums的[i + 1, nums.length)部分
+ nums.splice(i+1,nums.length - i, ...arr);
+ return;
+ }
+ }
+ }
+ nums.sort((a,b) => a - b); // 不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排列)。
+};
+
+//另一种
+var nextPermutation = function(nums) {
+ let i = nums.length - 2;
+ // 从右往左遍历拿到第一个左边小于右边的 i,此时 i 右边的数组是从右往左递增的
+ while (i >= 0 && nums[i] >= nums[i+1]){
+ i--;
+ }
+ if (i >= 0){
+ let j = nums.length - 1;
+ // 从右往左遍历拿到第一个大于nums[i]的数,因为之前nums[i]是第一个小于他右边的数,所以他的右边一定有大于他的数
+ while (j >= 0 && nums[j] <= nums[i]){
+ j--;
+ }
+ // 交换两个数
+ [nums[j], nums[i]] = [nums[i], nums[j]];
+ }
+ // 对 i 右边的数进行交换
+ // 因为 i 右边的数原来是从右往左递增的,把一个较小的值交换过来之后,仍然维持单调递增特性
+ // 此时头尾交换并向中间逼近就能获得 i 右边序列的最小值
+ let l = i + 1;
+ let r = nums.length - 1;
+ while (l < r){
+ [nums[l], nums[r]] = [nums[r], nums[l]];
+ l++;
+ r--;
+ }
+};
```
-----------------------
From 3ddd1a277b3c18cce0f2b687551da406f9a2a1ce Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 22:53:43 +0800
Subject: [PATCH 158/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A05.=20=E6=9C=80?=
=?UTF-8?q?=E9=95=BF=E5=9B=9E=E6=96=87=E5=AD=90=E4=B8=B2=20JavaScript?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0005.最长回文子串.md | 111 ++++++++++++++++++++++++++++++++++
1 file changed, 111 insertions(+)
diff --git a/problems/0005.最长回文子串.md b/problems/0005.最长回文子串.md
index c78b827c..5897495f 100644
--- a/problems/0005.最长回文子串.md
+++ b/problems/0005.最长回文子串.md
@@ -297,6 +297,117 @@ class Solution:
## JavaScript
```js
+//动态规划解法
+var longestPalindrome = function(s) {
+ const len = s.length;
+ // 布尔类型的dp[i][j]:表示区间范围[i,j] (注意是左闭右闭)的子串是否是回文子串,如果是dp[i][j]为true,否则为false
+ let dp = new Array(len).fill(false).map(() => new Array(len).fill(false));
+ // left起始位置 maxlenth回文串长度
+ let left = 0, maxlenth = 0;
+ for(let i = len - 1; i >= 0; i--){
+ for(let j = i; j < len; j++){
+ // 情况一:下标i 与 j相同,同一个字符例如a,当然是回文子串 j - i == 0
+ // 情况二:下标i 与 j相差为1,例如aa,也是文子串 j - i == 1
+ // 情况一和情况二 可以合并为 j - i <= 1
+ // 情况三:下标:i 与 j相差大于1的时候,例如cabac,此时s[i]与s[j]已经相同了,我们看i到j区间是不是回文子串就看aba是不是回文就可以了,那么aba的区间就是 i+1 与 j-1区间,这个区间是不是回文就看dp[i + 1][j - 1]===true
+ if(s[i] === s[j] && (j - i <= 1 || dp[i + 1][j - 1])){
+ dp[i][j] = true;
+ }
+ // 只要 dp[i][j] == true 成立,就表示子串 s[i..j] 是回文,此时记录回文长度和起始位置
+ if(dp[i][j] && j - i + 1 > maxlenth) {
+ maxlenth = j - i + 1; // 回文串长度
+ left = i; // 起始位置
+ }
+ }
+ }
+ return s.substr(left, maxlenth); // 找到子串
+};
+
+//双指针
+var longestPalindrome = function(s) {
+ let left = 0, right = 0, maxLength = 0;
+ const extend = (s, i, j, n) => {// s为字符串 i,j为双指针 n为字符串长度
+ while(i >= 0 && j < n && s[i] === s[j]){
+ if(j - i + 1 > maxLength){
+ left = i; // 更新开始位置
+ right = j; // 更新结尾位置
+ maxLength = j - i + 1; // 更新子串最大长度
+ }
+ // 指针移动
+ i--;
+ j++;
+ }
+ }
+ for(let i = 0; i < s.length; i++){
+ extend(s, i, i, s.length); // 以i为中心
+ extend(s, i, i + 1, s.length); // 以i和i+1为中心
+ }
+ return s.substr(left, maxLength);
+};
+
+//Manacher算法
+var longestPalindrome = function(s) {
+ const len = s.length;
+ if(len < 2) return s;
+ let maxLength = 1, index = 0;
+ //Manacher算法,利用回文对称的性质,根据i在上一个回文中心的臂长里的位置去判断i的回文性
+ //需要知道上一个回文中心,以及其臂长
+ let center = 0;
+ //注意这里使用了maxRight的而不是真实的臂长length,因为之后需要判断i在臂长的什么位置
+ //如果这里臂长用了length,之后还要 计算i - center 去和 length比较,太繁琐
+ let maxRight = 0;
+ //考虑到回文串的长度是偶数的情况,所以这里预处理一下字符串,每个字符间插入特殊字符,把可能性都化为奇数
+ //这个处理把回文串长度的可能性都化为了奇数
+ //#c#b#b#a#
+ //#c#b#a#b#d#
+ let ss = "";
+ for(let i = 0; i < s.length; i++){
+ ss += "#"+s[i];
+ }
+ ss += "#";
+ //需要维护一个每个位置臂长的信息数组positionLength
+ const pl = new Array(ss.length).fill(0);
+ //这里需要注意参考的是i关于center对称的点i'的回文性
+ //i' = 2*center - i;
+ //所以列下情况:
+ //1.i>maxRight,找不到i',无法参考,自己算自己的
+ //2.i<=maxRight:
+ //2.1 i= pl[i‘],大多少需要尝试扩散
+ //2.3 i>maxRight-pl[i'],pl[i']的臂长超过了center的臂长,根据对称性,i中心扩散到MaxRight处,
+ // s[2*i-maxRight] !== s[MaxRight]必不相等,所以pl[i] = maxRight-i;
+ //总结就是pl[i] = Math.min(maxRight-i,pl[i']);提示i= 0 && right maxRight){
+ center = i;
+ maxRight = pl[i] + i;
+ }
+ if (pl[i] * 2 + 1 > maxLength){
+ maxLength = pl[i]*2+1;
+ index = i - pl[i];
+ }
+ }
+ return ss.substr(index, maxLength).replace(/#/g,"");
+};
```
-----------------------
From a97988ede289ab6b93c029d14134267027b18651 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 23:07:36 +0800
Subject: [PATCH 159/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0844.=20=E6=AF=94?=
=?UTF-8?q?=E8=BE=83=E5=90=AB=E9=80=80=E6=A0=BC=E7=9A=84=E5=AD=97=E7=AC=A6?=
=?UTF-8?q?=E4=B8=B2=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0844.比较含退格的字符串.md | 58 +++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/problems/0844.比较含退格的字符串.md b/problems/0844.比较含退格的字符串.md
index 74455ace..a3199ebe 100644
--- a/problems/0844.比较含退格的字符串.md
+++ b/problems/0844.比较含退格的字符串.md
@@ -232,6 +232,64 @@ func backspaceCompare(s string, t string) bool {
```
JavaScript:
+```javascript
+// 双栈
+var backspaceCompare = function(s, t) {
+ const arrS = [], arrT = []; // 数组作为栈使用
+ for(let char of s){
+ char === '#' ? arrS.pop() : arrS.push(char);
+ }
+ for(let char of t){
+ char === '#' ? arrT.pop() : arrT.push(char);
+ }
+ return arrS.join('') === arrT.join(''); // 比较两个字符串是否相等
+};
+
+//双栈精简
+var backspaceCompare = function(s, t) {
+ const getString = s => {
+ let arrS = [];
+ for(let char of s){
+ char === '#' ? arrS.pop() : arrS.push(char);
+ }
+ return arrS.join('');
+ }
+ return getString(s) === getString(t);
+};
+
+//双指针
+var backspaceCompare = function(s, t) {
+ let sSkipNum = 0; // 记录s的#数量
+ let tSkipNum = 0; // 记录t的#数量
+ let i = s.length - 1, j = t.length - 1;
+ while(true) {
+ while(i >= 0){ // 从后向前,消除s的#
+ if(s[i] === '#') sSkipNum++;
+ else {
+ if (sSkipNum > 0) sSkipNum--;
+ else break;
+ }
+ i--;
+ }
+ while (j >= 0) { // 从后向前,消除t的#
+ if (t[j] === '#') tSkipNum++;
+ else {
+ if (tSkipNum > 0) tSkipNum--;
+ else break;
+ }
+ j--;
+ }
+ // 后半部分#消除完了,接下来比较s[i] != t[j]
+ if (i < 0 || j < 0) break; // s 或者t 遍历到头了
+ if (s[i] !== t[j]) return false;
+ i--;j--;
+ }
+ // 说明s和t同时遍历完毕
+ if (i == -1 && j == -1) return true;
+ return false;
+};
+
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
From 4d4cd5baceadfa6dea2515a80f55a1434e13d86f Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 23:26:57 +0800
Subject: [PATCH 160/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0841.=20=E9=92=A5?=
=?UTF-8?q?=E5=8C=99=E5=92=8C=E6=88=BF=E9=97=B4=20JavaScript=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0841.钥匙和房间.md | 49 +++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/problems/0841.钥匙和房间.md b/problems/0841.钥匙和房间.md
index d281dc5a..055a023c 100644
--- a/problems/0841.钥匙和房间.md
+++ b/problems/0841.钥匙和房间.md
@@ -220,6 +220,55 @@ func canVisitAllRooms(rooms [][]int) bool {
```
JavaScript:
+```javascript
+//DFS
+var canVisitAllRooms = function(rooms) {
+ const dfs = (key, rooms, visited) => {
+ if(visited[key]) return;
+ visited[key] = 1;
+ for(let k of rooms[key]){
+ // 深度优先搜索遍历
+ dfs(k, rooms, visited);
+ }
+ }
+ const visited = new Array(rooms.length).fill(false);
+ dfs(0, rooms, visited);
+ //检查是否都访问到了
+ for (let i of visited) {
+ if (!i) {
+ return false;
+ }
+ }
+ return true;
+};
+
+//BFS
+var canVisitAllRooms = function(rooms) {
+ const bfs = rooms => {
+ const visited = new Array(rooms.length).fill(0); // 标记房间是否被访问过
+ visited[0] = 1; // 0 号房间开始
+ const queue = []; //js数组作为队列使用
+ queue.push(0); // 0 号房间开始
+ // 广度优先搜索的过程
+ while(queue.length !== 0){
+ let key = queue[0];
+ queue.shift();
+ for(let k of rooms[key]){
+ if(!visited[k]){
+ queue.push(k);
+ visited[k] = 1;
+ }
+ }
+ }
+ // 检查房间是不是都遍历过了
+ for(let i of visited){
+ if(i === 0) return false;
+ }
+ return true;
+ }
+ return bfs(rooms);
+};
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
From 6a9fa6713a0259a0ff65b9ee10a9d25bb7dc8b3d Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Mon, 27 Sep 2021 23:51:56 +0800
Subject: [PATCH 161/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E132.=20=E5=88=86?=
=?UTF-8?q?=E5=89=B2=E5=9B=9E=E6=96=87=E4=B8=B2=20II=20JavaScript=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0132.分割回文串II.md | 36 +++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/problems/0132.分割回文串II.md b/problems/0132.分割回文串II.md
index f9cbd618..4cf86496 100644
--- a/problems/0132.分割回文串II.md
+++ b/problems/0132.分割回文串II.md
@@ -247,6 +247,42 @@ class Solution:
## JavaScript
```js
+var minCut = function(s) {
+ const len = s.length;
+ // 二维数组isPalindromic来保存整个字符串的回文情况
+ const isPalindromic = new Array(len).fill(false).map(() => new Array(len).fill(false));
+ for(let i = len - 1; i >= 0; i--){
+ for(let j = i; j < len; j++){
+ if(s[i] === s[j] && (j - i <= 1 || isPalindromic[i + 1][j - 1])){
+ isPalindromic[i][j] = true;
+ }
+ }
+ }
+ // dp[i]:范围是[0, i]的回文子串,最少分割次数是dp[i]
+ const dp = new Array(len).fill(0);
+ for(let i = 0; i < len; i++) dp[i] = i; // 初始化 dp[i]的最大值其实就是i,也就是把每个字符分割出来
+ for(let i = 1; i < len; i++){
+ if(isPalindromic[0][i]){ // 判断是不是回文子串
+ dp[i] = 0;
+ continue;
+ }
+ /*
+ 如果要对长度为[0, i]的子串进行分割,分割点为j。
+ 那么如果分割后,区间[j + 1, i]是回文子串,那么dp[i] 就等于 dp[j] + 1。
+ 这里可能有同学就不明白了,为什么只看[j + 1, i]区间,不看[0, j]区间是不是回文子串呢?
+ 那么在回顾一下dp[i]的定义: 范围是[0, i]的回文子串,最少分割次数是dp[i]。
+ [0, j]区间的最小切割数量,我们已经知道了就是dp[j]。
+ 此时就找到了递推关系,当切割点j在[0, i] 之间时候,dp[i] = dp[j] + 1;
+ 本题是要找到最少分割次数,所以遍历j的时候要取最小的dp[i]。dp[i] = Math.min(dp[i], dp[j] + 1);
+ */
+ for(let j = 0; j < i; j++){
+ if(isPalindromic[j + 1][i]){
+ dp[i] = Math.min(dp[i], dp[j] + 1);
+ }
+ }
+ }
+ return dp[len - 1];
+};
```
-----------------------
From 91d01d610c4c8e75b8d2789240f43a52bf8fe378 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 00:28:04 +0800
Subject: [PATCH 162/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E42.=20=E6=8E=A5?=
=?UTF-8?q?=E9=9B=A8=E6=B0=B4=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0042.接雨水.md | 99 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 99 insertions(+)
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index 16c788eb..5326dd7f 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -534,6 +534,105 @@ class Solution:
Go:
JavaScript:
+```javascript
+//双指针
+var trap = function(height) {
+ const len = height.length;
+ let sum = 0;
+ for(let i = 0; i < len; i++){
+ // 第一个柱子和最后一个柱子不接雨水
+ if(i == 0 || i == len - 1) continue;
+ let rHeight = height[i]; // 记录右边柱子的最高高度
+ let lHeight = height[i]; // 记录左边柱子的最高高度
+ for(let r = i + 1; r < len; r++){
+ if(height[r] > rHeight) rHeight = height[r];
+ }
+ for(let l = i - 1; l >= 0; l--){
+ if(height[l] > lHeight) lHeight = height[l];
+ }
+ let h = Math.min(lHeight, rHeight) - height[i];
+ if(h > 0) sum += h;
+ }
+ return sum;
+};
+
+//动态规划
+var trap = function(height) {
+ const len = height.length;
+ if(len <= 2) return 0;
+ const maxLeft = new Array(len).fill(0);
+ const maxRight = new Array(len).fill(0);
+ // 记录每个柱子左边柱子最大高度
+ maxLeft[0] = height[0];
+ for(let i = 1; i < len; i++){
+ maxLeft[i] = Math.max(height[i], maxLeft[i - 1]);
+ }
+ // 记录每个柱子右边柱子最大高度
+ maxRight[len - 1] = height[len - 1];
+ for(let i = len - 2; i >= 0; i--){
+ maxRight[i] = Math.max(height[i], maxRight[i + 1]);
+ }
+ // 求和
+ let sum = 0;
+ for(let i = 0; i < len; i++){
+ let count = Math.min(maxLeft[i], maxRight[i]) - height[i];
+ if(count > 0) sum += count;
+ }
+ return sum;
+};
+
+//单调栈 js数组作为栈
+var trap = function(height) {
+ const len = height.length;
+ if(len <= 2) return 0; // 可以不加
+ const st = [];// 存着下标,计算的时候用下标对应的柱子高度
+ st.push(0);
+ let sum = 0;
+ for(let i = 1; i < len; i++){
+ if(height[i] < height[st[st.length - 1]]){ // 情况一
+ st.push(i);
+ }
+ if (height[i] == height[st[st.length - 1]]) { // 情况二
+ st.pop(); // 其实这一句可以不加,效果是一样的,但处理相同的情况的思路却变了。
+ st.push(i);
+ } else { // 情况三
+ while (st.length !== 0 && height[i] > height[st[st.length - 1]]) { // 注意这里是while
+ let mid = st[st.length - 1];
+ st.pop();
+ if (st.length !== 0) {
+ let h = Math.min(height[st[st.length - 1]], height[i]) - height[mid];
+ let w = i - st[st.length - 1] - 1; // 注意减一,只求中间宽度
+ sum += h * w;
+ }
+ }
+ st.push(i);
+ }
+ }
+ return sum;
+};
+
+//单调栈 简洁版本 只处理情况三
+var trap = function(height) {
+ const len = height.length;
+ if(len <= 2) return 0; // 可以不加
+ const st = [];// 存着下标,计算的时候用下标对应的柱子高度
+ st.push(0);
+ let sum = 0;
+ for(let i = 1; i < len; i++){ // 只处理的情况三,其实是把情况一和情况二融合了
+ while (st.length !== 0 && height[i] > height[st[st.length - 1]]) { // 注意这里是while
+ let mid = st[st.length - 1];
+ st.pop();
+ if (st.length !== 0) {
+ let h = Math.min(height[st[st.length - 1]], height[i]) - height[mid];
+ let w = i - st[st.length - 1] - 1; // 注意减一,只求中间宽度
+ sum += h * w;
+ }
+ }
+ st.push(i);
+ }
+ return sum;
+};
+```
C:
From 766af43f4e4409f953b96c27ab7ff252a5802b35 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 00:38:48 +0800
Subject: [PATCH 163/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E129.=20=E6=B1=82?=
=?UTF-8?q?=E6=A0=B9=E8=8A=82=E7=82=B9=E5=88=B0=E5=8F=B6=E8=8A=82=E7=82=B9?=
=?UTF-8?q?=E6=95=B0=E5=AD=97=E4=B9=8B=E5=92=8C=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0129.求根到叶子节点数字之和.md | 42 +++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/problems/0129.求根到叶子节点数字之和.md b/problems/0129.求根到叶子节点数字之和.md
index 696042a8..9a671404 100644
--- a/problems/0129.求根到叶子节点数字之和.md
+++ b/problems/0129.求根到叶子节点数字之和.md
@@ -241,6 +241,48 @@ class Solution:
Go:
JavaScript:
+```javascript
+var sumNumbers = function(root) {
+ const listToInt = path => {
+ let sum = 0;
+ for(let num of path){
+ // sum * 10 表示进位
+ sum = sum * 10 + num;
+ }
+ return sum;
+ }
+ const recur = root =>{
+ if (root.left == null && root.right == null) {
+ // 当是叶子节点的时候,开始处理
+ res += listToInt(path);
+ return;
+ }
+
+ if (root.left != null){
+ // 注意有回溯
+ path.push(root.left.val);
+ recur(root.left);
+ path.pop();
+ }
+ if (root.right != null){
+ // 注意有回溯
+ path.push(root.right.val);
+ recur(root.right);
+ path.pop();
+ }
+ return;
+ };
+ const path = new Array();
+ let res = 0;
+ // 如果节点为0,那么就返回0
+ if (root == null) return 0;
+ // 首先将根节点放到集合中
+ path.push(root.val);
+ // 开始递归
+ recur(root);
+ return res;
+};
+```
From 46c0b8d596c0d986a2fbe1963d14f7808f15d675 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 01:02:53 +0800
Subject: [PATCH 164/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E684.=20=E5=86=97?=
=?UTF-8?q?=E4=BD=99=E8=BF=9E=E6=8E=A5=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0684.冗余连接.md | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/problems/0684.冗余连接.md b/problems/0684.冗余连接.md
index bfbdeba9..654ef469 100644
--- a/problems/0684.冗余连接.md
+++ b/problems/0684.冗余连接.md
@@ -303,6 +303,43 @@ func findRedundantConnection(edges [][]int) []int {
## JavaScript
```js
+const n = 1005;
+const father = new Array(n);
+// 并查集里寻根的过程
+const find = u => {
+ return u == father[u] ? u : father[u] = find(father[u]);
+};
+
+// 将v->u 这条边加入并查集
+const join = (u, v) => {
+ u = find(u);
+ v = find(v);
+ if(u == v) return;
+ father[v] = u;
+};
+
+// 判断 u 和 v是否找到同一个根,本题用不上
+const same = (u, v) => {
+ u = find(u);
+ v = find(v);
+ return u == v;
+};
+
+/**
+ * @param {number[][]} edges
+ * @return {number[]}
+ */
+var findRedundantConnection = function(edges) {
+ // 并查集初始化
+ for(let i = 0; i < n; i++){
+ father[i] = i;
+ }
+ for(let i = 0; i < edges.length; i++){
+ if(same(edges[i][0], edges[i][1])) return edges[i];
+ else join(edges[i][0], edges[i][1]);
+ }
+ return null;
+};
```
-----------------------
From 5c669a05a1bebe0437616bd441a4147a34abc0cb Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 01:23:08 +0800
Subject: [PATCH 165/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E685.=20=E5=86=97?=
=?UTF-8?q?=E4=BD=99=E8=BF=9E=E6=8E=A5=20II=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0685.冗余连接II.md | 85 +++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)
diff --git a/problems/0685.冗余连接II.md b/problems/0685.冗余连接II.md
index 404813f3..b7a41372 100644
--- a/problems/0685.冗余连接II.md
+++ b/problems/0685.冗余连接II.md
@@ -515,6 +515,91 @@ func findRedundantDirectedConnection(edges [][]int) []int {
## JavaScript
```js
+const N = 1010; // 如题:二维数组大小的在3到1000范围内
+const father = new Array(N);
+let n; // 边的数量
+
+// 并查集里寻根的过程
+const find = u => {
+ return u == father[u] ? u : father[u] = find(father[u]);
+};
+
+// 将v->u 这条边加入并查集
+const join = (u, v) => {
+ u = find(u);
+ v = find(v);
+ if(u == v) return;
+ father[v] = u;
+};
+
+// 判断 u 和 v是否找到同一个根
+const same = (u, v) => {
+ u = find(u);
+ v = find(v);
+ return u == v;
+};
+
+// 在有向图里找到删除的那条边,使其变成树
+const getRemoveEdge = edges => {
+ // 初始化并查集
+ for (let i = 1; i <= n; i++) {
+ father[i] = i;
+ }
+ for (let i = 0; i < n; i++) { // 遍历所有的边
+ if (same(edges[i][0], edges[i][1])) { // 构成有向环了,就是要删除的边
+ return edges[i];
+ }
+ join(edges[i][0], edges[i][1]);
+ }
+ return [];
+}
+
+// 删一条边之后判断是不是树
+const isTreeAfterRemoveEdge = (edges, deleteEdge) => {
+ // 初始化并查集
+ for (let i = 1; i <= n; i++) {
+ father[i] = i;
+ }
+ for (let i = 0; i < n; i++) {
+ if (i == deleteEdge) continue;
+ if (same(edges[i][0], edges[i][1])) { // 构成有向环了,一定不是树
+ return false;
+ }
+ join(edges[i][0], edges[i][1]);
+ }
+ return true;
+}
+
+/**
+ * @param {number[][]} edges
+ * @return {number[]}
+ */
+var findRedundantDirectedConnection = function(edges) {
+ n = edges.length;// 边的数量
+ const inDegree = new Array(n+1).fill(0); // 记录节点入度
+ for (let i = 0; i < n; i++) {
+ inDegree[edges[i][1]]++; // 统计入度
+ }
+ let vec = [];// 记录入度为2的边(如果有的话就两条边)
+ // 找入度为2的节点所对应的边,注意要倒叙,因为优先返回最后出现在二维数组中的答案
+ for (let i = n - 1; i >= 0; i--) {
+ if (inDegree[edges[i][1]] == 2) {
+ vec.push(i);
+ }
+ }
+ // 处理图中情况1 和 情况2
+ // 如果有入度为2的节点,那么一定是两条边里删一个,看删哪个可以构成树
+ if (vec.length > 0) {
+ if (isTreeAfterRemoveEdge(edges, vec[0])) {
+ return edges[vec[0]];
+ } else {
+ return edges[vec[1]];
+ }
+ }
+ // 处理图中情况3
+ // 明确没有入度为2的情况,那么一定有有向环,找到构成环的边返回就可以了
+ return getRemoveEdge(edges);
+};
```
-----------------------
From b5a1b4663cdbb869c77d4d7269cb759cea739a2c Mon Sep 17 00:00:00 2001
From: ArthurP
Date: Mon, 27 Sep 2021 19:59:46 +0100
Subject: [PATCH 166/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200491.=E9=80=92?=
=?UTF-8?q?=E5=A2=9E=E5=AD=90=E5=BA=8F=E5=88=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0491.递增子序列.md | 56 +++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md
index ea113f4b..82e768e7 100644
--- a/problems/0491.递增子序列.md
+++ b/problems/0491.递增子序列.md
@@ -313,7 +313,63 @@ var findSubsequences = function(nums) {
```
+C:
+```c
+int* path;
+int pathTop;
+int** ans;
+int ansTop;
+int* length;
+void copy() {
+ int* tempPath = (int*)malloc(sizeof(int) * pathTop);
+ memcpy(tempPath, path, pathTop * sizeof(int));
+ length[ansTop] = pathTop;
+ ans[ansTop++] = tempPath;
+}
+int find(int* uset, int usetSize, int key) {
+ int i;
+ for(i = 0; i < usetSize; i++) {
+ if(uset[i] == key)
+ return 1;
+ }
+ return 0;
+}
+
+void backTracking(int* nums, int numsSize, int startIndex) {
+ if(pathTop > 1) {
+ copy();
+ }
+ int* uset = (int*)malloc(sizeof(int) * numsSize);
+ int usetTop = 0;
+ int i;
+ for(i = startIndex; i < numsSize; i++) {
+ if((pathTop > 0 && nums[i] < path[pathTop - 1]) || find(uset, usetTop, nums[i]))
+ continue;
+ uset[usetTop++] = nums[i];
+ path[pathTop++] = nums[i];
+ backTracking(nums, numsSize, i + 1);
+ pathTop--;
+ }
+}
+
+int** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
+ path = (int*)malloc(sizeof(int) * numsSize);
+ ans = (int**)malloc(sizeof(int*) * 33000);
+ length = (int*)malloc(sizeof(int*) * 33000);
+ pathTop = ansTop = 0;
+
+ backTracking(nums, numsSize, 0);
+
+ *returnSize = ansTop;
+ *returnColumnSizes = (int*)malloc(sizeof(int) * ansTop);
+ int i;
+ for(i = 0; i < ansTop; i++) {
+ (*returnColumnSizes)[i] = length[i];
+ }
+ return ans;
+}
+```
-----------------------
From d39a7287a21e3c733bc84ac32faae19748fa9424 Mon Sep 17 00:00:00 2001
From: ArthurP
Date: Mon, 27 Sep 2021 20:02:02 +0100
Subject: [PATCH 167/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200491.=E9=80=92?=
=?UTF-8?q?=E5=A2=9E=E5=AD=90=E5=BA=8F=E5=88=97.md=20C=E8=AF=AD=E8=A8=80?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0491.递增子序列.md | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md
index 82e768e7..9f61ae45 100644
--- a/problems/0491.递增子序列.md
+++ b/problems/0491.递增子序列.md
@@ -320,6 +320,7 @@ int pathTop;
int** ans;
int ansTop;
int* length;
+//将当前path中的内容复制到ans中
void copy() {
int* tempPath = (int*)malloc(sizeof(int) * pathTop);
memcpy(tempPath, path, pathTop * sizeof(int));
@@ -327,6 +328,7 @@ void copy() {
ans[ansTop++] = tempPath;
}
+//查找uset中是否存在值为key的元素
int find(int* uset, int usetSize, int key) {
int i;
for(i = 0; i < usetSize; i++) {
@@ -337,6 +339,7 @@ int find(int* uset, int usetSize, int key) {
}
void backTracking(int* nums, int numsSize, int startIndex) {
+ //当path中元素大于1个时,将path拷贝到ans中
if(pathTop > 1) {
copy();
}
@@ -344,16 +347,21 @@ void backTracking(int* nums, int numsSize, int startIndex) {
int usetTop = 0;
int i;
for(i = startIndex; i < numsSize; i++) {
+ //若当前元素小于path中最后一位元素 || 在树的同一层找到了相同的元素,则continue
if((pathTop > 0 && nums[i] < path[pathTop - 1]) || find(uset, usetTop, nums[i]))
continue;
+ //将当前元素放入uset
uset[usetTop++] = nums[i];
+ //将当前元素放入path
path[pathTop++] = nums[i];
backTracking(nums, numsSize, i + 1);
+ //回溯
pathTop--;
}
}
int** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
+ //辅助数组初始化
path = (int*)malloc(sizeof(int) * numsSize);
ans = (int**)malloc(sizeof(int*) * 33000);
length = (int*)malloc(sizeof(int*) * 33000);
@@ -361,6 +369,7 @@ int** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnCol
backTracking(nums, numsSize, 0);
+ //设置数组中返回元素个数,以及每个一维数组的长度
*returnSize = ansTop;
*returnColumnSizes = (int*)malloc(sizeof(int) * ansTop);
int i;
From 7f75ee1b562559c9ef1c4d0d38365bf3ab57195e Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Tue, 28 Sep 2021 08:44:37 +0800
Subject: [PATCH 168/284] =?UTF-8?q?=E4=BF=AE=E6=94=B9=200704=20=E4=BA=8C?=
=?UTF-8?q?=E5=88=86=E6=9F=A5=E6=89=BE=20JavaScript=E7=89=88=E6=9C=AC=20?=
=?UTF-8?q?=E5=B7=A6=E9=97=AD=E5=8F=B3=E9=97=AD=E5=8C=BA=E9=97=B4=20?=
=?UTF-8?q?=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0704.二分查找.md | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md
index 67809000..5b8ff8c7 100644
--- a/problems/0704.二分查找.md
+++ b/problems/0704.二分查找.md
@@ -288,15 +288,16 @@ func search(nums []int, target int) int {
* @param {number} target
* @return {number}
*/
+/**
var search = function(nums, target) {
- let left = 0, right = nums.length;
- // 使用左闭右开区间 [left, right)
- while (left < right) {
+ let left = 0, right = nums.length - 1;
+ // 使用左闭右闭区间
+ while (left <= right) {
let mid = left + Math.floor((right - left)/2);
if (nums[mid] > target) {
- right = mid; // 去左区间寻找
+ right = mid - 1; // 去左面闭区间寻找
} else if (nums[mid] < target) {
- left = mid + 1; // 去右区间寻找
+ left = mid + 1; // 去右面闭区间寻找
} else {
return mid;
}
From ed9ebe1c4e894575100ecdafe9bfaf5ad698814a Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Tue, 28 Sep 2021 09:05:09 +0800
Subject: [PATCH 169/284] =?UTF-8?q?=E4=BF=AE=E6=94=B9=200077=20=E7=BB=84?=
=?UTF-8?q?=E5=90=88=E4=BC=98=E5=8C=96=20c++=E4=BB=A3=E7=A0=81=20=E6=B2=A1?=
=?UTF-8?q?=E6=9C=89=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0077.组合优化.md | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/problems/0077.组合优化.md b/problems/0077.组合优化.md
index 136ceb34..ff447bc1 100644
--- a/problems/0077.组合优化.md
+++ b/problems/0077.组合优化.md
@@ -22,7 +22,7 @@
大家先回忆一下[77. 组合]给出的回溯法的代码:
-```
+```c++
class Solution {
private:
vector> result; // 存放符合条件结果的集合
@@ -54,7 +54,7 @@ public:
在遍历的过程中有如下代码:
-```
+```c++
for (int i = startIndex; i <= n; i++) {
path.push_back(i);
backtracking(n, k, i + 1);
@@ -78,7 +78,7 @@ for (int i = startIndex; i <= n; i++) {
**如果for循环选择的起始位置之后的元素个数 已经不足 我们需要的元素个数了,那么就没有必要搜索了**。
注意代码中i,就是for循环里选择的起始位置。
-```
+```c++
for (int i = startIndex; i <= n; i++) {
```
@@ -100,13 +100,13 @@ for (int i = startIndex; i <= n; i++) {
所以优化之后的for循环是:
-```
+```c++
for (int i = startIndex; i <= n - (k - path.size()) + 1; i++) // i为本次搜索的起始位置
```
优化后整体代码如下:
-```
+```c++
class Solution {
private:
vector> result;
From 31ac0ef5b3f270a722c79d7fbb90a278ce7bf851 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 11:10:17 +0800
Subject: [PATCH 170/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E143.=20=E9=87=8D?=
=?UTF-8?q?=E6=8E=92=E9=93=BE=E8=A1=A8=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0143.重排链表.md | 104 ++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
diff --git a/problems/0143.重排链表.md b/problems/0143.重排链表.md
index 2b4e68b7..07c3bb40 100644
--- a/problems/0143.重排链表.md
+++ b/problems/0143.重排链表.md
@@ -351,6 +351,110 @@ class Solution:
Go:
JavaScript:
+```javascript
+// 方法一 使用数组存储节点
+var reorderList = function(head, s = [], tmp) {
+ let cur = head;
+ // list是数组,可以使用下标随机访问
+ const list = [];
+ while(cur != null){
+ list.push(cur);
+ cur = cur.next;
+ }
+ cur = head; // 重新回到头部
+ let l = 1, r = list.length - 1; // 注意左边是从1开始
+ let count = 0;
+ while(l <= r){
+ if(count % 2 == 0){
+ // even
+ cur.next = list[r];
+ r--;
+ } else {
+ // odd
+ cur.next = list[l];
+ l++;
+ }
+ // 每一次指针都需要移动
+ cur = cur.next;
+ count++;
+ }
+ // 当是偶数的话,需要做额外处理
+ if(list.length % 2 == 0){
+ cur.next = list[l];
+ cur = cur.next;
+ }
+ // 注意结尾要结束一波
+ cur.next = null;
+}
+
+// 方法二 使用双端队列的方法来解决 js中运行很慢
+var reorderList = function(head, s = [], tmp) {
+ // js数组作为双端队列
+ const deque = [];
+ // 这里是取head的下一个节点,head不需要再入队了,避免造成重复
+ let cur = head.next;
+ while(cur != null){
+ deque.push(cur);
+ cur = cur.next;
+ }
+ cur = head; // 回到头部
+ let count = 0;
+ while(deque.length !== 0){
+ if(count % 2 == 0){
+ // even,取出队列右边尾部的值
+ cur.next = deque.pop();
+ } else {
+ // odd, 取出队列左边头部的值
+ cur.next = deque.shift();
+ }
+ cur = cur.next;
+ count++;
+ }
+ cur.next = null;
+}
+
+//方法三 将链表分割成两个链表,然后把第二个链表反转,之后在通过两个链表拼接成新的链表
+var reorderList = function(head, s = [], tmp) {
+ const reverseList = head => {
+ let headNode = new ListNode(0);
+ let cur = head;
+ let next = null;
+ while(cur != null){
+ next = cur.next;
+ cur.next = headNode.next;
+ headNode.next = cur;
+ cur = next;
+ }
+ return headNode.next;
+ }
+
+ let fast = head, slow = head;
+ //求出中点
+ while(fast.next != null && fast.next.next != null){
+ slow = slow.next;
+ fast = fast.next.next;
+ }
+ //right就是右半部分 12345 就是45 1234 就是34
+ let right = slow.next;
+ //断开左部分和右部分
+ slow.next = null;
+ //反转右部分 right就是反转后右部分的起点
+ right = reverseList(right);
+ //左部分的起点
+ let left = head;
+ //进行左右部分来回连接
+ //这里左部分的节点个数一定大于等于右部分的节点个数 因此只判断right即可
+ while (right != null) {
+ let curLeft = left.next;
+ left.next = right;
+ left = curLeft;
+
+ let curRight = right.next;
+ right.next = left;
+ right = curRight;
+ }
+}
+```
-----------------------
From 8605f26bd762cd734e697ba7da9b3085d8f9db4d Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 11:43:20 +0800
Subject: [PATCH 171/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E127.=20=E5=8D=95?=
=?UTF-8?q?=E8=AF=8D=E6=8E=A5=E9=BE=99=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0127.单词接龙.md | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/problems/0127.单词接龙.md b/problems/0127.单词接龙.md
index e38453ef..c52f2ba5 100644
--- a/problems/0127.单词接龙.md
+++ b/problems/0127.单词接龙.md
@@ -141,6 +141,40 @@ public int ladderLength(String beginWord, String endWord, List wordList)
## Go
## JavaScript
+```javascript
+var ladderLength = function(beginWord, endWord, wordList) {
+ // 将wordList转成Set,提高查询速度
+ const wordSet = new Set(wordList);
+ // Set元素个数为0 或者 endWord没有在wordSet出现,直接返回0
+ if (wordSet.size === 0 || !wordSet.has(endWord)) return 0;
+ // 记录word是否访问过
+ const visitMap = new Map();//
+ // 初始化队列
+ const queue = [];
+ queue.push(beginWord);
+ // 初始化visitMap
+ visitMap.set(beginWord, 1);
+
+ while(queue.length !== 0){
+ let word = queue.shift(); // 删除队首元素,将它的值存放在word
+ let path = visitMap.get(word); // 这个word的路径长度
+ for(let i = 0; i < word.length; i++){ // 遍历单词的每个字符
+ for (let c = 97; c <= 122; c++) { // 对应26个字母ASCII值 从'a' 到 'z' 遍历替换
+ // 拼串得到新的字符串
+ let newWord = word.slice(0, i) + String.fromCharCode(c) + word.slice(i + 1);
+ if(newWord === endWord) return path + 1; // 找到了end,返回path+1
+ // wordSet出现了newWord,并且newWord没有被访问过
+ if(wordSet.has(newWord) && !visitMap.has(newWord)) {
+ // 添加访问信息
+ visitMap.set(newWord, path + 1);
+ queue.push(newWord);
+ }
+ }
+ }
+ }
+ return 0;
+};
+```
-----------------------
From 09a045de9e0741c26c121ed44e81bd448b090e8f Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 12:13:43 +0800
Subject: [PATCH 172/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E84.=20=E6=9F=B1?=
=?UTF-8?q?=E7=8A=B6=E5=9B=BE=E4=B8=AD=E6=9C=80=E5=A4=A7=E7=9A=84=E7=9F=A9?=
=?UTF-8?q?=E5=BD=A2=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0084.柱状图中最大的矩形.md | 75 +++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/problems/0084.柱状图中最大的矩形.md b/problems/0084.柱状图中最大的矩形.md
index 57df4161..4e11d966 100644
--- a/problems/0084.柱状图中最大的矩形.md
+++ b/problems/0084.柱状图中最大的矩形.md
@@ -321,4 +321,79 @@ class Solution:
return result
```
+JavaScript:
+```javascript
+//动态规划 js中运行速度最快
+var largestRectangleArea = function(heights) {
+ const len = heights.length;
+ const minLeftIndex = new Array(len);
+ const maxRigthIndex = new Array(len);
+ // 记录每个柱子 左边第一个小于该柱子的下标
+ minLeftIndex[0] = -1; // 注意这里初始化,防止下面while死循环
+ for(let i = 1; i < len; i++) {
+ let t = i - 1;
+ // 这里不是用if,而是不断向左寻找的过程
+ while(t >= 0 && heights[t] >= heights[i]) t = minLeftIndex[t];
+ minLeftIndex[i] = t;
+ }
+ // 记录每个柱子 右边第一个小于该柱子的下标
+ maxRigthIndex[len - 1] = len; // 注意这里初始化,防止下面while死循环
+ for(let i = len - 2; i >= 0; i--){
+ let t = i + 1;
+ // 这里不是用if,而是不断向右寻找的过程
+ while(t < len && heights[t] >= heights[i]) t = maxRigthIndex[t];
+ maxRigthIndex[i] = t;
+ }
+ // 求和
+ let maxArea = 0;
+ for(let i = 0; i < len; i++){
+ let sum = heights[i] * (maxRigthIndex[i] - minLeftIndex[i] - 1);
+ maxArea = Math.max(maxArea , sum);
+ }
+ return maxArea;
+};
+
+//单调栈
+var largestRectangleArea = function(heights) {
+ let maxArea = 0;
+ const stack = [];
+ heights = [0,...heights,0]; // 数组头部加入元素0 数组尾部加入元素0
+ for(let i = 0; i < heights.length; i++){
+ if(heights[i] > heights[stack[stack.length-1]]){ // 情况三
+ stack.push(i);
+ } else if(heights[i] === heights[stack[stack.length-1]]){ // 情况二
+ stack.pop(); // 这个可以加,可以不加,效果一样,思路不同
+ stack.push(i);
+ } else { // 情况一
+ while(heights[i] < heights[stack[stack.length-1]]){// 当前bar比栈顶bar矮
+ const stackTopIndex = stack.pop();// 栈顶元素出栈,并保存栈顶bar的索引
+ let w = i - stack[stack.length -1] - 1;
+ let h = heights[stackTopIndex]
+ // 计算面积,并取最大面积
+ maxArea = Math.max(maxArea, w * h);
+ }
+ stack.push(i);// 当前bar比栈顶bar高了,入栈
+ }
+ }
+ return maxArea;
+};
+
+//单调栈 简洁
+var largestRectangleArea = function(heights) {
+ let maxArea = 0;
+ const stack = [];
+ heights = [0,...heights,0]; // 数组头部加入元素0 数组尾部加入元素0
+ for(let i = 0; i < heights.length; i++){ // 只用考虑情况一 当前遍历的元素heights[i]小于栈顶元素heights[stack[stack.length-1]]]的情况
+ while(heights[i] < heights[stack[stack.length-1]]){// 当前bar比栈顶bar矮
+ const stackTopIndex = stack.pop();// 栈顶元素出栈,并保存栈顶bar的索引
+ let w = i - stack[stack.length -1] - 1;
+ let h = heights[stackTopIndex]
+ // 计算面积,并取最大面积
+ maxArea = Math.max(maxArea, w * h);
+ }
+ stack.push(i);// 当前bar比栈顶bar高了,入栈
+ }
+ return maxArea;
+};
+```
From 827cc69b7141a7dedfa2c4363c5d827d81383c47 Mon Sep 17 00:00:00 2001
From: jerryfishcode <91447694+jerryfishcode@users.noreply.github.com>
Date: Tue, 28 Sep 2021 12:29:50 +0800
Subject: [PATCH 173/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E52.=20N=E7=9A=87?=
=?UTF-8?q?=E5=90=8E=20II=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0052.N皇后II.md | 44 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/problems/0052.N皇后II.md b/problems/0052.N皇后II.md
index 1a34f763..d7d7feb8 100644
--- a/problems/0052.N皇后II.md
+++ b/problems/0052.N皇后II.md
@@ -101,4 +101,48 @@ public:
```
# 其他语言补充
+JavaScript
+```javascript
+var totalNQueens = function(n) {
+ let count = 0;
+ const backtracking = (n, row, chessboard) => {
+ if(row === n){
+ count++;
+ return;
+ }
+ for(let col = 0; col < n; col++){
+ if(isValid(row, col, chessboard, n)) { // 验证合法就可以放
+ chessboard[row][col] = 'Q'; // 放置皇后
+ backtracking(n, row + 1, chessboard);
+ chessboard[row][col] = '.'; // 回溯
+ }
+ }
+ }
+ const isValid = (row, col, chessboard, n) => {
+ // 检查列
+ for(let i = 0; i < row; i++){ // 这是一个剪枝
+ if(chessboard[i][col] === 'Q'){
+ return false;
+ }
+ }
+ // 检查 45度角是否有皇后
+ for(let i = row - 1, j = col - 1; i >= 0 && j >= 0; i--, j--){
+ if(chessboard[i][j] === 'Q'){
+ return false;
+ }
+ }
+ // 检查 135度角是否有皇后
+ for(let i = row - 1, j = col + 1; i >= 0 && j < n; i--, j++){
+ if(chessboard[i][j] === 'Q'){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ const chessboard = new Array(n).fill([]).map(() => new Array(n).fill('.'));
+ backtracking(n, 0, chessboard);
+ return count;
+};
+```
From 089c8325f5e66617b861c0b7ed368d8ea8d026a6 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Tue, 28 Sep 2021 14:05:37 +0800
Subject: [PATCH 174/284] =?UTF-8?q?=E8=A7=A3=E5=86=B3=200455=20=E5=88=86?=
=?UTF-8?q?=E5=8F=91=E9=A5=BC=E5=B9=B2=20JavaScript=20=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B2=A1=E6=9C=89=E6=A0=B7=E5=BC=8F=E9=97=AE?=
=?UTF-8?q?=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0455.分发饼干.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md
index bae1566c..abd4712b 100644
--- a/problems/0455.分发饼干.md
+++ b/problems/0455.分发饼干.md
@@ -200,7 +200,7 @@ func findContentChildren(g []int, s []int) int {
```
Javascript:
-```
+```js
var findContentChildren = function(g, s) {
g = g.sort((a, b) => a - b)
s = s.sort((a, b) => a - b)
From 8c03e8d213cbc62a85ab66f97bf2b09179f69e7a Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Tue, 28 Sep 2021 15:44:04 +0800
Subject: [PATCH 175/284] Update
---
problems/0093.复原IP地址.md | 93 ++++++++++++-------------------------
problems/其他/参与本项目.md | 4 ++
2 files changed, 34 insertions(+), 63 deletions(-)
diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md
index 52db821a..7639bea2 100644
--- a/problems/0093.复原IP地址.md
+++ b/problems/0093.复原IP地址.md
@@ -8,7 +8,7 @@
-## 93.复原IP地址
+# 93.复原IP地址
[力扣题目链接](https://leetcode-cn.com/problems/restore-ip-addresses/)
@@ -19,31 +19,31 @@
例如:"0.1.2.201" 和 "192.168.1.1" 是 有效的 IP 地址,但是 "0.011.255.245"、"192.168.1.312" 和 "192.168@1.1" 是 无效的 IP 地址。
示例 1:
-输入:s = "25525511135"
-输出:["255.255.11.135","255.255.111.35"]
+* 输入:s = "25525511135"
+* 输出:["255.255.11.135","255.255.111.35"]
示例 2:
-输入:s = "0000"
-输出:["0.0.0.0"]
+* 输入:s = "0000"
+* 输出:["0.0.0.0"]
示例 3:
-输入:s = "1111"
-输出:["1.1.1.1"]
+* 输入:s = "1111"
+* 输出:["1.1.1.1"]
示例 4:
-输入:s = "010010"
-输出:["0.10.0.10","0.100.1.0"]
+* 输入:s = "010010"
+* 输出:["0.10.0.10","0.100.1.0"]
示例 5:
-输入:s = "101023"
-输出:["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
+* 输入:s = "101023"
+* 输出:["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
提示:
-0 <= s.length <= 3000
-s 仅由数字组成
+* 0 <= s.length <= 3000
+* s 仅由数字组成
-## 思路
+# 思路
做这道题目之前,最好先把[131.分割回文串](https://programmercarl.com/0131.分割回文串.html)这个做了。
@@ -114,7 +114,7 @@ if (pointNum == 3) { // 逗点数量为3时,分隔结束
代码如下:
-```
+```CPP
for (int i = startIndex; i < s.size(); i++) {
if (isValid(s, startIndex, i)) { // 判断 [startIndex,i] 这个区间的子串是否合法
s.insert(s.begin() + i + 1 , '.'); // 在i的后面插入一个逗点
@@ -138,7 +138,7 @@ for (int i = startIndex; i < s.size(); i++) {
代码如下:
-```
+```CPP
// 判断字符串s在左闭又闭区间[start, end]所组成的数字是否合法
bool isValid(const string& s, int start, int end) {
if (start > end) {
@@ -237,7 +237,7 @@ public:
```
-## 总结
+# 总结
在[131.分割回文串](https://programmercarl.com/0131.分割回文串.html)中我列举的分割字符串的难点,本题都覆盖了。
@@ -249,9 +249,9 @@ public:
-## 其他语言版本
+# 其他语言版本
-java 版本:
+## java
```java
class Solution {
@@ -308,7 +308,9 @@ class Solution {
}
```
-python版本:
+## python
+
+python2:
```python
class Solution:
def restoreIpAddresses(self, s: str) -> List[str]:
@@ -338,6 +340,8 @@ class Solution:
backtrack(s, 0)
return res
```
+
+python3:
```python
class Solution(object):
def restoreIpAddresses(self, s):
@@ -366,47 +370,8 @@ class Solution(object):
return ans```
```
-```python3
-class Solution:
- def __init__(self) -> None:
- self.s = ""
- self.res = []
- def isVaild(self, s: str) -> bool:
- if len(s) > 1 and s[0] == "0":
- return False
-
- if 0 <= int(s) <= 255:
- return True
-
- return False
-
- def backTrack(self, path: List[str], start: int) -> None:
- if start == len(self.s) and len(path) == 4:
- self.res.append(".".join(path))
- return
-
- for end in range(start + 1, len(self.s) + 1):
- # 剪枝
- # 保证切割完,s没有剩余的字符。
- if len(self.s) - end > 3 * (4 - len(path) - 1):
- continue
- if self.isVaild(self.s[start:end]):
- # 在参数处,更新状态,实则创建一个新的变量
- # 不会影响当前的状态,当前的path变量没有改变
- # 因此递归完不用path.pop()
- self.backTrack(path + [self.s[start:end]], end)
-
- def restoreIpAddresses(self, s: str) -> List[str]:
- # prune
- if len(s) > 3 * 4:
- return []
- self.s = s
- self.backTrack([], 0)
- return self.res
-```
-
-JavaScript:
+## JavaScript
```js
/**
@@ -435,8 +400,10 @@ var restoreIpAddresses = function(s) {
}
};
```
-Go:
-> 回溯(对于前导 0的IP(特别注意s[startIndex]=='0'的判断,不应该写成s[startIndex]==0,因为s截取出来不是数字))
+
+## Go
+
+回溯(对于前导 0的IP(特别注意s[startIndex]=='0'的判断,不应该写成s[startIndex]==0,因为s截取出来不是数字))
```go
func restoreIpAddresses(s string) []string {
@@ -476,7 +443,7 @@ func isNormalIp(s string,startIndex,end int)bool{
```
-C:
+## C
```c
//记录结果
char** result;
diff --git a/problems/其他/参与本项目.md b/problems/其他/参与本项目.md
index cfa75439..76a2c61e 100644
--- a/problems/其他/参与本项目.md
+++ b/problems/其他/参与本项目.md
@@ -9,3 +9,7 @@
git add之前,要git diff 查看一下,本次提交所修改的代码是不是 自己修改的,是否 误删,或者误加的文件。
提交代码,不要使用git push -f 这种命令,要足够了解 -f 意味着什么。
+
+
+不用非要写出牛逼的代码才能提交PR,只要发现 文章中有任何问题,或者错别字,都欢迎提交PR,成为contributor。
+
From 70ce257d4569a77b1c310708559da35f59a5ae2c Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Tue, 28 Sep 2021 15:54:27 +0800
Subject: [PATCH 176/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0001.两数之和.md | 2 +-
problems/0005.最长回文子串.md | 8 ++++----
problems/0015.三数之和.md | 2 +-
problems/0017.电话号码的字母组合.md | 2 +-
problems/0018.四数之和.md | 2 +-
problems/0019.删除链表的倒数第N个节点.md | 2 +-
problems/0020.有效的括号.md | 2 +-
problems/0024.两两交换链表中的节点.md | 2 +-
problems/0027.移除元素.md | 2 +-
problems/0028.实现strStr.md | 2 +-
problems/0031.下一个排列.md | 6 +++---
...排序数组中查找元素的第一个和最后一个位置.md | 6 +++---
problems/0035.搜索插入位置.md | 2 +-
problems/0037.解数独.md | 2 +-
problems/0039.组合总和.md | 2 +-
problems/0040.组合总和II.md | 2 +-
problems/0042.接雨水.md | 4 ++--
problems/0045.跳跃游戏II.md | 2 +-
problems/0046.全排列.md | 2 +-
problems/0047.全排列II.md | 2 +-
problems/0051.N皇后.md | 2 +-
problems/0052.N皇后II.md | 7 ++++++-
problems/0053.最大子序和.md | 2 +-
problems/0053.最大子序和(动态规划).md | 2 +-
problems/0055.跳跃游戏.md | 2 +-
problems/0056.合并区间.md | 2 +-
problems/0059.螺旋矩阵II.md | 2 +-
problems/0062.不同路径.md | 2 +-
problems/0063.不同路径II.md | 2 +-
problems/0070.爬楼梯.md | 2 +-
problems/0070.爬楼梯完全背包版本.md | 2 +-
problems/0072.编辑距离.md | 7 +------
problems/0077.组合.md | 2 +-
problems/0077.组合优化.md | 2 +-
problems/0078.子集.md | 2 +-
problems/0084.柱状图中最大的矩形.md | 13 ++++++++++++-
problems/0090.子集II.md | 2 +-
problems/0093.复原IP地址.md | 2 +-
problems/0096.不同的二叉搜索树.md | 2 +-
problems/0098.验证二叉搜索树.md | 2 +-
problems/0100.相同的树.md | 6 +++---
problems/0101.对称二叉树.md | 2 +-
problems/0102.二叉树的层序遍历.md | 2 +-
problems/0104.二叉树的最大深度.md | 2 +-
.../0106.从中序与后序遍历序列构造二叉树.md | 2 +-
problems/0108.将有序数组转换为二叉搜索树.md | 2 +-
problems/0110.平衡二叉树.md | 2 +-
problems/0111.二叉树的最小深度.md | 2 +-
problems/0112.路径总和.md | 2 +-
problems/0115.不同的子序列.md | 2 +-
.../0116.填充每个节点的下一个右侧节点指针.md | 6 +++---
problems/0121.买卖股票的最佳时机.md | 2 +-
problems/0122.买卖股票的最佳时机II.md | 2 +-
.../0122.买卖股票的最佳时机II(动态规划).md | 2 +-
problems/0123.买卖股票的最佳时机III.md | 2 +-
problems/0127.单词接龙.md | 4 ++--
problems/0129.求根到叶子节点数字之和.md | 9 ++++++++-
problems/0131.分割回文串.md | 2 +-
problems/0132.分割回文串II.md | 6 +++---
problems/0134.加油站.md | 2 +-
problems/0135.分发糖果.md | 2 +-
problems/0139.单词拆分.md | 2 +-
problems/0141.环形链表.md | 6 +++---
problems/0142.环形链表II.md | 2 +-
problems/0143.重排链表.md | 10 ++++------
problems/0150.逆波兰表达式求值.md | 2 +-
problems/0151.翻转字符串里的单词.md | 2 +-
problems/0160.相交链表.md | 13 ++++++++++++-
problems/0188.买卖股票的最佳时机IV.md | 2 +-
problems/0189.旋转数组.md | 8 ++++----
problems/0198.打家劫舍.md | 2 +-
problems/0202.快乐数.md | 2 +-
problems/0203.移除链表元素.md | 2 +-
problems/0205.同构字符串.md | 6 +++---
problems/0206.翻转链表.md | 2 +-
problems/0209.长度最小的子数组.md | 2 +-
problems/0213.打家劫舍II.md | 2 +-
problems/0216.组合总和III.md | 2 +-
problems/0222.完全二叉树的节点个数.md | 2 +-
problems/0225.用队列实现栈.md | 2 +-
problems/0226.翻转二叉树.md | 2 +-
problems/0232.用栈实现队列.md | 2 +-
problems/0234.回文链表.md | 6 +++---
problems/0235.二叉搜索树的最近公共祖先.md | 2 +-
problems/0236.二叉树的最近公共祖先.md | 2 +-
problems/0239.滑动窗口最大值.md | 2 +-
problems/0242.有效的字母异位词.md | 2 +-
problems/0257.二叉树的所有路径.md | 2 +-
problems/0279.完全平方数.md | 2 +-
problems/0283.移动零.md | 6 +++---
problems/0300.最长上升子序列.md | 2 +-
problems/0309.最佳买卖股票时机含冷冻期.md | 2 +-
problems/0322.零钱兑换.md | 2 +-
problems/0332.重新安排行程.md | 2 +-
problems/0337.打家劫舍III.md | 2 +-
problems/0343.整数拆分.md | 2 +-
problems/0344.反转字符串.md | 2 +-
problems/0347.前K个高频元素.md | 2 +-
problems/0349.两个数组的交集.md | 2 +-
problems/0376.摆动序列.md | 2 +-
problems/0377.组合总和Ⅳ.md | 2 +-
problems/0383.赎金信.md | 2 +-
problems/0392.判断子序列.md | 2 +-
problems/0404.左叶子之和.md | 2 +-
problems/0406.根据身高重建队列.md | 2 +-
problems/0416.分割等和子集.md | 2 +-
problems/0435.无重叠区间.md | 2 +-
problems/0450.删除二叉搜索树中的节点.md | 2 +-
problems/0452.用最少数量的箭引爆气球.md | 2 +-
problems/0454.四数相加II.md | 2 +-
problems/0455.分发饼干.md | 2 +-
problems/0459.重复的子字符串.md | 2 +-
problems/0463.岛屿的周长.md | 9 ++++++++-
problems/0474.一和零.md | 2 +-
problems/0491.递增子序列.md | 2 +-
problems/0494.目标和.md | 2 +-
problems/0496.下一个更大元素I.md | 13 ++++++++++++-
problems/0501.二叉搜索树中的众数.md | 2 +-
problems/0503.下一个更大元素II.md | 13 ++++++++++++-
problems/0509.斐波那契数.md | 2 +-
problems/0513.找树左下角的值.md | 2 +-
problems/0516.最长回文子序列.md | 2 +-
problems/0518.零钱兑换II.md | 2 +-
problems/0530.二叉搜索树的最小绝对差.md | 2 +-
problems/0538.把二叉搜索树转换为累加树.md | 2 +-
problems/0541.反转字符串II.md | 2 +-
problems/0583.两个字符串的删除操作.md | 2 +-
problems/0617.合并二叉树.md | 2 +-
problems/0647.回文子串.md | 2 +-
problems/0649.Dota2参议院.md | 6 +++---
problems/0654.最大二叉树.md | 2 +-
problems/0657.机器人能否返回原点.md | 6 +++---
problems/0669.修剪二叉搜索树.md | 2 +-
problems/0673.最长递增子序列的个数.md | 6 +++---
problems/0674.最长连续递增序列.md | 2 +-
problems/0684.冗余连接.md | 18 +++++++++---------
problems/0685.冗余连接II.md | 8 +++-----
problems/0700.二叉搜索树中的搜索.md | 2 +-
problems/0701.二叉搜索树中的插入操作.md | 2 +-
problems/0704.二分查找.md | 2 +-
problems/0707.设计链表.md | 2 +-
problems/0714.买卖股票的最佳时机含手续费.md | 2 +-
...4.买卖股票的最佳时机含手续费(动态规划).md | 2 +-
problems/0718.最长重复子数组.md | 2 +-
problems/0724.寻找数组的中心索引.md | 6 +++---
problems/0738.单调递增的数字.md | 2 +-
problems/0739.每日温度.md | 6 +++---
problems/0746.使用最小花费爬楼梯.md | 2 +-
problems/0763.划分字母区间.md | 2 +-
problems/0841.钥匙和房间.md | 6 +++---
problems/0844.比较含退格的字符串.md | 6 +++---
problems/0860.柠檬水找零.md | 2 +-
problems/0922.按奇偶排序数组II.md | 6 +++---
problems/0925.长按键入.md | 6 +++---
problems/0941.有效的山脉数组.md | 10 +++++-----
problems/0968.监控二叉树.md | 2 +-
problems/0977.有序数组的平方.md | 2 +-
problems/1002.查找常用字符.md | 4 ++--
problems/1005.K次取反后最大化的数组和.md | 2 +-
problems/1035.不相交的线.md | 2 +-
problems/1047.删除字符串中的所有相邻重复项.md | 2 +-
problems/1049.最后一块石头的重量II.md | 2 +-
problems/1143.最长公共子序列.md | 2 +-
problems/1207.独一无二的出现次数.md | 4 ++--
problems/1221.分割平衡字符串.md | 4 ++--
problems/1356.根据数字二进制下1的数目排序.md | 6 +++---
problems/1365.有多少小于当前数字的数字.md | 4 ++--
problems/1382.将二叉搜索树变平衡.md | 8 ++++----
...(n)的算法居然超时了,此时的n究竟是多大?.md | 2 +-
problems/为了绝杀编辑距离,卡尔做了三步铺垫.md | 2 +-
problems/二叉树中递归带着回溯.md | 2 +-
problems/二叉树总结篇.md | 2 +-
problems/二叉树理论基础.md | 2 +-
problems/二叉树的统一迭代法.md | 2 +-
problems/二叉树的迭代遍历.md | 2 +-
problems/二叉树的递归遍历.md | 2 +-
.../关于时间复杂度,你不知道的都在这里!.md | 2 +-
problems/剑指Offer05.替换空格.md | 2 +-
problems/剑指Offer58-II.左旋转字符串.md | 2 +-
problems/动态规划-股票问题总结篇.md | 2 +-
problems/动态规划总结篇.md | 6 +++---
problems/动态规划理论基础.md | 2 +-
problems/双指针总结.md | 2 +-
problems/哈希表总结.md | 2 +-
problems/哈希表理论基础.md | 2 +-
problems/回溯总结.md | 2 +-
problems/回溯算法去重问题的另一种写法.md | 2 +-
problems/回溯算法理论基础.md | 2 +-
problems/字符串总结.md | 2 +-
problems/数组总结篇.md | 2 +-
problems/数组理论基础.md | 2 +-
problems/栈与队列总结.md | 2 +-
problems/栈与队列理论基础.md | 2 +-
problems/根据身高重建队列(vector原理讲解).md | 2 +-
problems/算法模板.md | 2 +-
problems/背包总结篇.md | 2 +-
problems/背包理论基础01背包-1.md | 2 +-
problems/背包理论基础01背包-2.md | 2 +-
problems/背包问题理论基础多重背包.md | 2 +-
problems/背包问题理论基础完全背包.md | 2 +-
problems/贪心算法总结篇.md | 2 +-
problems/贪心算法理论基础.md | 2 +-
problems/链表总结篇.md | 2 +-
problems/链表理论基础.md | 2 +-
problems/面试题02.07.链表相交.md | 2 +-
205 files changed, 340 insertions(+), 286 deletions(-)
diff --git a/problems/0001.两数之和.md b/problems/0001.两数之和.md
index a6381eff..0ef73c6a 100644
--- a/problems/0001.两数之和.md
+++ b/problems/0001.两数之和.md
@@ -253,4 +253,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0005.最长回文子串.md b/problems/0005.最长回文子串.md
index c78b827c..626ceaf6 100644
--- a/problems/0005.最长回文子串.md
+++ b/problems/0005.最长回文子串.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 5.最长回文子串
[力扣题目链接](https://leetcode-cn.com/problems/longest-palindromic-substring/)
@@ -299,10 +299,10 @@ class Solution:
```js
```
+
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
+
diff --git a/problems/0015.三数之和.md b/problems/0015.三数之和.md
index d3d7f61e..d00b76bd 100644
--- a/problems/0015.三数之和.md
+++ b/problems/0015.三数之和.md
@@ -441,4 +441,4 @@ func threeSum(_ nums: [Int]) -> [[Int]] {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0017.电话号码的字母组合.md b/problems/0017.电话号码的字母组合.md
index ef485a39..3dff97e5 100644
--- a/problems/0017.电话号码的字母组合.md
+++ b/problems/0017.电话号码的字母组合.md
@@ -475,4 +475,4 @@ char ** letterCombinations(char * digits, int* returnSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0018.四数之和.md b/problems/0018.四数之和.md
index e283b291..ddeb3c96 100644
--- a/problems/0018.四数之和.md
+++ b/problems/0018.四数之和.md
@@ -407,4 +407,4 @@ func fourSum(_ nums: [Int], _ target: Int) -> [[Int]] {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0019.删除链表的倒数第N个节点.md b/problems/0019.删除链表的倒数第N个节点.md
index 85e3eb48..f54b1629 100644
--- a/problems/0019.删除链表的倒数第N个节点.md
+++ b/problems/0019.删除链表的倒数第N个节点.md
@@ -233,4 +233,4 @@ func removeNthFromEnd(_ head: ListNode?, _ n: Int) -> ListNode? {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0020.有效的括号.md b/problems/0020.有效的括号.md
index 5b02f9ee..918a3560 100644
--- a/problems/0020.有效的括号.md
+++ b/problems/0020.有效的括号.md
@@ -290,4 +290,4 @@ var isValid = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0024.两两交换链表中的节点.md b/problems/0024.两两交换链表中的节点.md
index 75a5f739..19c2a06e 100644
--- a/problems/0024.两两交换链表中的节点.md
+++ b/problems/0024.两两交换链表中的节点.md
@@ -283,4 +283,4 @@ func swapPairs(_ head: ListNode?) -> ListNode? {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md
index 4afd347a..21216945 100644
--- a/problems/0027.移除元素.md
+++ b/problems/0027.移除元素.md
@@ -290,4 +290,4 @@ int removeElement(int* nums, int numsSize, int val){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0028.实现strStr.md b/problems/0028.实现strStr.md
index 481be2ed..35bec96d 100644
--- a/problems/0028.实现strStr.md
+++ b/problems/0028.实现strStr.md
@@ -902,4 +902,4 @@ var strStr = function (haystack, needle) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0031.下一个排列.md b/problems/0031.下一个排列.md
index 05321a9a..587885e4 100644
--- a/problems/0031.下一个排列.md
+++ b/problems/0031.下一个排列.md
@@ -1,4 +1,3 @@
-
@@ -9,6 +8,7 @@
+
# 31.下一个排列
[力扣题目链接](https://leetcode-cn.com/problems/next-permutation/)
@@ -134,9 +134,9 @@ class Solution {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
index 68dd797d..1d7cabe3 100644
--- a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
+++ b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 34. 在排序数组中查找元素的第一个和最后一个位置
给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。
@@ -398,9 +398,9 @@ class Solution:
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md
index a536f0ec..b25bfe54 100644
--- a/problems/0035.搜索插入位置.md
+++ b/problems/0035.搜索插入位置.md
@@ -313,4 +313,4 @@ func searchInsert(_ nums: [Int], _ target: Int) -> Int {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0037.解数独.md b/problems/0037.解数独.md
index 94c5c198..468cd3a6 100644
--- a/problems/0037.解数独.md
+++ b/problems/0037.解数独.md
@@ -556,4 +556,4 @@ void solveSudoku(char** board, int boardSize, int* boardColSize) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0039.组合总和.md b/problems/0039.组合总和.md
index 4836de9c..369d1cb9 100644
--- a/problems/0039.组合总和.md
+++ b/problems/0039.组合总和.md
@@ -405,4 +405,4 @@ int** combinationSum(int* candidates, int candidatesSize, int target, int* retur
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0040.组合总和II.md b/problems/0040.组合总和II.md
index d6f4dac9..6d0460eb 100644
--- a/problems/0040.组合总和II.md
+++ b/problems/0040.组合总和II.md
@@ -458,4 +458,4 @@ int** combinationSum2(int* candidates, int candidatesSize, int target, int* retu
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index 16c788eb..43daa1b0 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
> 这个图就是大厂面试经典题目,接雨水! 最常青藤的一道题,面试官百出不厌!
# 42. 接雨水
@@ -577,4 +577,4 @@ int trap(int* height, int heightSize) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0045.跳跃游戏II.md b/problems/0045.跳跃游戏II.md
index 8dd59838..31b6ee2e 100644
--- a/problems/0045.跳跃游戏II.md
+++ b/problems/0045.跳跃游戏II.md
@@ -236,4 +236,4 @@ var jump = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md
index 001c249e..bba7dd6a 100644
--- a/problems/0046.全排列.md
+++ b/problems/0046.全排列.md
@@ -315,4 +315,4 @@ var permute = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0047.全排列II.md b/problems/0047.全排列II.md
index c5de73c7..085b686e 100644
--- a/problems/0047.全排列II.md
+++ b/problems/0047.全排列II.md
@@ -338,4 +338,4 @@ func backTring(nums,subRes []int,res *[][]int,used []bool){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0051.N皇后.md b/problems/0051.N皇后.md
index c141c326..fa2d2ab7 100644
--- a/problems/0051.N皇后.md
+++ b/problems/0051.N皇后.md
@@ -499,4 +499,4 @@ var solveNQueens = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0052.N皇后II.md b/problems/0052.N皇后II.md
index 1a34f763..4c08071b 100644
--- a/problems/0052.N皇后II.md
+++ b/problems/0052.N皇后II.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 52. N皇后II
题目链接:https://leetcode-cn.com/problems/n-queens-ii/
@@ -102,3 +102,8 @@ public:
# 其他语言补充
+-----------------------
+* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
+* B站视频:[代码随想录](https://space.bilibili.com/525438321)
+* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
+
diff --git a/problems/0053.最大子序和.md b/problems/0053.最大子序和.md
index 18d3007e..da67bfd7 100644
--- a/problems/0053.最大子序和.md
+++ b/problems/0053.最大子序和.md
@@ -216,4 +216,4 @@ var maxSubArray = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0053.最大子序和(动态规划).md b/problems/0053.最大子序和(动态规划).md
index 4c2a2944..ebf4541c 100644
--- a/problems/0053.最大子序和(动态规划).md
+++ b/problems/0053.最大子序和(动态规划).md
@@ -192,4 +192,4 @@ const maxSubArray = nums => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md
index c9ebe0fe..0c936131 100644
--- a/problems/0055.跳跃游戏.md
+++ b/problems/0055.跳跃游戏.md
@@ -161,4 +161,4 @@ var canJump = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0056.合并区间.md b/problems/0056.合并区间.md
index 82ca29e6..6332d5a9 100644
--- a/problems/0056.合并区间.md
+++ b/problems/0056.合并区间.md
@@ -248,4 +248,4 @@ var merge = function (intervals) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0059.螺旋矩阵II.md b/problems/0059.螺旋矩阵II.md
index 733ec749..99750f60 100644
--- a/problems/0059.螺旋矩阵II.md
+++ b/problems/0059.螺旋矩阵II.md
@@ -542,4 +542,4 @@ int** generateMatrix(int n, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0062.不同路径.md b/problems/0062.不同路径.md
index ce29cca1..4d0381e0 100644
--- a/problems/0062.不同路径.md
+++ b/problems/0062.不同路径.md
@@ -333,4 +333,4 @@ var uniquePaths = function(m, n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0063.不同路径II.md b/problems/0063.不同路径II.md
index c01846bd..322de75e 100644
--- a/problems/0063.不同路径II.md
+++ b/problems/0063.不同路径II.md
@@ -341,4 +341,4 @@ var uniquePathsWithObstacles = function(obstacleGrid) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0070.爬楼梯.md b/problems/0070.爬楼梯.md
index 4f049e4a..54d026ab 100644
--- a/problems/0070.爬楼梯.md
+++ b/problems/0070.爬楼梯.md
@@ -301,4 +301,4 @@ var climbStairs = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md
index 4410dbaf..6fc1a50d 100644
--- a/problems/0070.爬楼梯完全背包版本.md
+++ b/problems/0070.爬楼梯完全背包版本.md
@@ -192,4 +192,4 @@ func climbStairs(n int) int {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0072.编辑距离.md b/problems/0072.编辑距离.md
index 2045c1fd..ca8e85b8 100644
--- a/problems/0072.编辑距离.md
+++ b/problems/0072.编辑距离.md
@@ -51,7 +51,6 @@ exection -> execution (插入 'u')
接下来我依然使用动规五部曲,对本题做一个详细的分析:
------------------------
### 1. 确定dp数组(dp table)以及下标的含义
@@ -61,7 +60,6 @@ exection -> execution (插入 'u')
用i来表示也可以! 但我统一以下标i-1为结尾的字符串,在下面的递归公式中会容易理解一点。
------------------------
### 2. 确定递推公式
@@ -156,7 +154,6 @@ for (int i = 0; i <= word1.size(); i++) dp[i][0] = i;
for (int j = 0; j <= word2.size(); j++) dp[0][j] = j;
```
------------------------
### 4. 确定遍历顺序
@@ -187,7 +184,6 @@ for (int i = 1; i <= word1.size(); i++) {
}
}
```
------------------------
### 5. 举例推导dp数组
@@ -220,7 +216,6 @@ public:
};
```
------------------------
## 其他语言版本
@@ -338,4 +333,4 @@ const minDistance = (word1, word2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0077.组合.md b/problems/0077.组合.md
index c63e45f5..6f6f89a6 100644
--- a/problems/0077.组合.md
+++ b/problems/0077.组合.md
@@ -627,4 +627,4 @@ int** combine(int n, int k, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0077.组合优化.md b/problems/0077.组合优化.md
index 136ceb34..02b30d3d 100644
--- a/problems/0077.组合优化.md
+++ b/problems/0077.组合优化.md
@@ -300,4 +300,4 @@ int** combine(int n, int k, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0078.子集.md b/problems/0078.子集.md
index 747b89d1..39f6ed5d 100644
--- a/problems/0078.子集.md
+++ b/problems/0078.子集.md
@@ -325,4 +325,4 @@ int** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes)
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0084.柱状图中最大的矩形.md b/problems/0084.柱状图中最大的矩形.md
index 57df4161..a0c30099 100644
--- a/problems/0084.柱状图中最大的矩形.md
+++ b/problems/0084.柱状图中最大的矩形.md
@@ -1,3 +1,10 @@
+
+
+
+
+
+
+欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
# 84.柱状图中最大的矩形
@@ -321,4 +328,8 @@ class Solution:
return result
```
-
+-----------------------
+* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
+* B站视频:[代码随想录](https://space.bilibili.com/525438321)
+* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
+
diff --git a/problems/0090.子集II.md b/problems/0090.子集II.md
index e970d752..d2a9279f 100644
--- a/problems/0090.子集II.md
+++ b/problems/0090.子集II.md
@@ -353,4 +353,4 @@ int** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColum
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md
index 7639bea2..26103318 100644
--- a/problems/0093.复原IP地址.md
+++ b/problems/0093.复原IP地址.md
@@ -524,4 +524,4 @@ char ** restoreIpAddresses(char * s, int* returnSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0096.不同的二叉搜索树.md b/problems/0096.不同的二叉搜索树.md
index 68ab11c8..76d7d353 100644
--- a/problems/0096.不同的二叉搜索树.md
+++ b/problems/0096.不同的二叉搜索树.md
@@ -234,4 +234,4 @@ const numTrees =(n) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0098.验证二叉搜索树.md b/problems/0098.验证二叉搜索树.md
index 6d054634..c7e5b4e6 100644
--- a/problems/0098.验证二叉搜索树.md
+++ b/problems/0098.验证二叉搜索树.md
@@ -529,4 +529,4 @@ var isValidBST = function (root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0100.相同的树.md b/problems/0100.相同的树.md
index 6ffaf3cb..c7431c5e 100644
--- a/problems/0100.相同的树.md
+++ b/problems/0100.相同的树.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 100. 相同的树
[力扣题目链接](https://leetcode-cn.com/problems/same-tree/)
@@ -242,9 +242,9 @@ Go:
JavaScript:
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0101.对称二叉树.md b/problems/0101.对称二叉树.md
index 3abf26cb..196e0b58 100644
--- a/problems/0101.对称二叉树.md
+++ b/problems/0101.对称二叉树.md
@@ -582,4 +582,4 @@ var isSymmetric = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md
index 5128d6ec..df1790c3 100644
--- a/problems/0102.二叉树的层序遍历.md
+++ b/problems/0102.二叉树的层序遍历.md
@@ -1778,4 +1778,4 @@ JavaScript:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md
index 516cf5f1..4162de80 100644
--- a/problems/0104.二叉树的最大深度.md
+++ b/problems/0104.二叉树的最大深度.md
@@ -586,4 +586,4 @@ var maxDepth = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md
index a9639d8f..68f4419a 100644
--- a/problems/0106.从中序与后序遍历序列构造二叉树.md
+++ b/problems/0106.从中序与后序遍历序列构造二叉树.md
@@ -823,4 +823,4 @@ var buildTree = function(preorder, inorder) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0108.将有序数组转换为二叉搜索树.md b/problems/0108.将有序数组转换为二叉搜索树.md
index f7bff27d..9b260db1 100644
--- a/problems/0108.将有序数组转换为二叉搜索树.md
+++ b/problems/0108.将有序数组转换为二叉搜索树.md
@@ -362,4 +362,4 @@ var sortedArrayToBST = function (nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0110.平衡二叉树.md b/problems/0110.平衡二叉树.md
index 43a49758..bd2fe432 100644
--- a/problems/0110.平衡二叉树.md
+++ b/problems/0110.平衡二叉树.md
@@ -624,4 +624,4 @@ var isBalanced = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0111.二叉树的最小深度.md b/problems/0111.二叉树的最小深度.md
index 12eadd60..3cfed997 100644
--- a/problems/0111.二叉树的最小深度.md
+++ b/problems/0111.二叉树的最小深度.md
@@ -413,4 +413,4 @@ var minDepth = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md
index da62452c..9bb470e6 100644
--- a/problems/0112.路径总和.md
+++ b/problems/0112.路径总和.md
@@ -711,4 +711,4 @@ var pathsum = function(root, targetsum) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0115.不同的子序列.md b/problems/0115.不同的子序列.md
index 908682dd..3de9b3e1 100644
--- a/problems/0115.不同的子序列.md
+++ b/problems/0115.不同的子序列.md
@@ -274,4 +274,4 @@ const numDistinct = (s, t) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0116.填充每个节点的下一个右侧节点指针.md b/problems/0116.填充每个节点的下一个右侧节点指针.md
index e43d79b0..be6c31e8 100644
--- a/problems/0116.填充每个节点的下一个右侧节点指针.md
+++ b/problems/0116.填充每个节点的下一个右侧节点指针.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 116. 填充每个节点的下一个右侧节点指针
[力扣题目链接](https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node/)
@@ -255,9 +255,9 @@ const connect = root => {
};
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0121.买卖股票的最佳时机.md b/problems/0121.买卖股票的最佳时机.md
index b08e4193..9592c442 100644
--- a/problems/0121.买卖股票的最佳时机.md
+++ b/problems/0121.买卖股票的最佳时机.md
@@ -360,4 +360,4 @@ const maxProfit = prices => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0122.买卖股票的最佳时机II.md b/problems/0122.买卖股票的最佳时机II.md
index 4bbe9e5e..591226ba 100644
--- a/problems/0122.买卖股票的最佳时机II.md
+++ b/problems/0122.买卖股票的最佳时机II.md
@@ -286,4 +286,4 @@ int maxProfit(int* prices, int pricesSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0122.买卖股票的最佳时机II(动态规划).md b/problems/0122.买卖股票的最佳时机II(动态规划).md
index c324d392..31a8e6dc 100644
--- a/problems/0122.买卖股票的最佳时机II(动态规划).md
+++ b/problems/0122.买卖股票的最佳时机II(动态规划).md
@@ -246,4 +246,4 @@ const maxProfit = (prices) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0123.买卖股票的最佳时机III.md b/problems/0123.买卖股票的最佳时机III.md
index 6a849c80..80aa740f 100644
--- a/problems/0123.买卖股票的最佳时机III.md
+++ b/problems/0123.买卖股票的最佳时机III.md
@@ -324,4 +324,4 @@ const maxProfit = prices => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0127.单词接龙.md b/problems/0127.单词接龙.md
index e38453ef..5d0426ed 100644
--- a/problems/0127.单词接龙.md
+++ b/problems/0127.单词接龙.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 127. 单词接龙
[力扣题目链接](https://leetcode-cn.com/problems/word-ladder/)
@@ -147,4 +147,4 @@ public int ladderLength(String beginWord, String endWord, List wordList)
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0129.求根到叶子节点数字之和.md b/problems/0129.求根到叶子节点数字之和.md
index 696042a8..4d9c7524 100644
--- a/problems/0129.求根到叶子节点数字之和.md
+++ b/problems/0129.求根到叶子节点数字之和.md
@@ -1,3 +1,10 @@
+
+
+
+
+
+
+欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
# 129. 求根节点到叶节点数字之和
[力扣题目链接](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/)
@@ -248,4 +255,4 @@ JavaScript:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md
index 08f091aa..81aa1522 100644
--- a/problems/0131.分割回文串.md
+++ b/problems/0131.分割回文串.md
@@ -424,4 +424,4 @@ var partition = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0132.分割回文串II.md b/problems/0132.分割回文串II.md
index f9cbd618..2569068e 100644
--- a/problems/0132.分割回文串II.md
+++ b/problems/0132.分割回文串II.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 132. 分割回文串 II
[力扣题目链接](https://leetcode-cn.com/problems/palindrome-partitioning-ii/)
@@ -249,9 +249,9 @@ class Solution:
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0134.加油站.md b/problems/0134.加油站.md
index 526efb14..65bff8e9 100644
--- a/problems/0134.加油站.md
+++ b/problems/0134.加油站.md
@@ -379,4 +379,4 @@ int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0135.分发糖果.md b/problems/0135.分发糖果.md
index 526b5870..dddb4488 100644
--- a/problems/0135.分发糖果.md
+++ b/problems/0135.分发糖果.md
@@ -242,4 +242,4 @@ var candy = function(ratings) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0139.单词拆分.md b/problems/0139.单词拆分.md
index 969d2ce7..b3158cb3 100644
--- a/problems/0139.单词拆分.md
+++ b/problems/0139.单词拆分.md
@@ -319,4 +319,4 @@ const wordBreak = (s, wordDict) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0141.环形链表.md b/problems/0141.环形链表.md
index 34b8d25f..ccebbc4e 100644
--- a/problems/0141.环形链表.md
+++ b/problems/0141.环形链表.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 141. 环形链表
给定一个链表,判断链表中是否有环。
@@ -116,9 +116,9 @@ class Solution:
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0142.环形链表II.md b/problems/0142.环形链表II.md
index bfa779a2..52ff7686 100644
--- a/problems/0142.环形链表II.md
+++ b/problems/0142.环形链表II.md
@@ -334,4 +334,4 @@ extension ListNode: Equatable {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0143.重排链表.md b/problems/0143.重排链表.md
index 2b4e68b7..382ed35c 100644
--- a/problems/0143.重排链表.md
+++ b/problems/0143.重排链表.md
@@ -221,7 +221,6 @@ public class ReorderList {
}
}
--------------------------------------------------------------------------
// 方法一 Java实现,使用数组存储节点
class Solution {
public void reorderList(ListNode head) {
@@ -260,7 +259,6 @@ public class ReorderList {
cur.next = null;
}
}
--------------------------------------------------------------------------
// 方法二:使用双端队列,简化了数组的操作,代码相对于前者更简洁(避免一些边界条件)
class Solution {
public void reorderList(ListNode head) {
@@ -352,11 +350,11 @@ Go:
JavaScript:
------------------------
+
+
+-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
+
diff --git a/problems/0150.逆波兰表达式求值.md b/problems/0150.逆波兰表达式求值.md
index 36652109..859a6d98 100644
--- a/problems/0150.逆波兰表达式求值.md
+++ b/problems/0150.逆波兰表达式求值.md
@@ -248,4 +248,4 @@ class Solution:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0151.翻转字符串里的单词.md b/problems/0151.翻转字符串里的单词.md
index c4a9c7e0..7902a398 100644
--- a/problems/0151.翻转字符串里的单词.md
+++ b/problems/0151.翻转字符串里的单词.md
@@ -553,4 +553,4 @@ func reverseWord(_ s: inout [Character]) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0160.相交链表.md b/problems/0160.相交链表.md
index 42b2ee56..ce7296b3 100644
--- a/problems/0160.相交链表.md
+++ b/problems/0160.相交链表.md
@@ -1,3 +1,14 @@
+
+
+
+
+
+
+欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
同:[链表:链表相交](https://programmercarl.com/面试题02.07.链表相交.html)
-
+-----------------------
+* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
+* B站视频:[代码随想录](https://space.bilibili.com/525438321)
+* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
+
diff --git a/problems/0188.买卖股票的最佳时机IV.md b/problems/0188.买卖股票的最佳时机IV.md
index a166db72..a0520fb4 100644
--- a/problems/0188.买卖股票的最佳时机IV.md
+++ b/problems/0188.买卖股票的最佳时机IV.md
@@ -331,4 +331,4 @@ var maxProfit = function(k, prices) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0189.旋转数组.md b/problems/0189.旋转数组.md
index 70aec5fe..a08ee83e 100644
--- a/problems/0189.旋转数组.md
+++ b/problems/0189.旋转数组.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 189. 旋转数组
给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
@@ -149,10 +149,10 @@ var rotate = function (nums, k) {
};
```
+
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
+
diff --git a/problems/0198.打家劫舍.md b/problems/0198.打家劫舍.md
index c8645c48..4bf8a81a 100644
--- a/problems/0198.打家劫舍.md
+++ b/problems/0198.打家劫舍.md
@@ -198,4 +198,4 @@ const rob = nums => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0202.快乐数.md b/problems/0202.快乐数.md
index 43c9d753..8f2e3bae 100644
--- a/problems/0202.快乐数.md
+++ b/problems/0202.快乐数.md
@@ -284,4 +284,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0203.移除链表元素.md b/problems/0203.移除链表元素.md
index c4f187e8..61c3e8ef 100644
--- a/problems/0203.移除链表元素.md
+++ b/problems/0203.移除链表元素.md
@@ -362,4 +362,4 @@ func removeElements(head *ListNode, val int) *ListNode {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0205.同构字符串.md b/problems/0205.同构字符串.md
index 5d20aa4a..421d29a8 100644
--- a/problems/0205.同构字符串.md
+++ b/problems/0205.同构字符串.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 205. 同构字符串
[力扣题目链接](https://leetcode-cn.com/problems/isomorphic-strings/)
@@ -121,9 +121,9 @@ func isIsomorphic(s string, t string) bool {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 45196386..3814b53d 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -375,4 +375,4 @@ func reverse(pre: ListNode?, cur: ListNode?) -> ListNode? {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0209.长度最小的子数组.md b/problems/0209.长度最小的子数组.md
index 7c3fd0e7..fe3657c0 100644
--- a/problems/0209.长度最小的子数组.md
+++ b/problems/0209.长度最小的子数组.md
@@ -297,4 +297,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0213.打家劫舍II.md b/problems/0213.打家劫舍II.md
index 332d3218..044769d5 100644
--- a/problems/0213.打家劫舍II.md
+++ b/problems/0213.打家劫舍II.md
@@ -174,4 +174,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0216.组合总和III.md b/problems/0216.组合总和III.md
index d7ab6cf7..a6660d7a 100644
--- a/problems/0216.组合总和III.md
+++ b/problems/0216.组合总和III.md
@@ -454,4 +454,4 @@ int** combinationSum3(int k, int n, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0222.完全二叉树的节点个数.md b/problems/0222.完全二叉树的节点个数.md
index 13017f7f..13f9f54d 100644
--- a/problems/0222.完全二叉树的节点个数.md
+++ b/problems/0222.完全二叉树的节点个数.md
@@ -455,4 +455,4 @@ var countNodes = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0225.用队列实现栈.md b/problems/0225.用队列实现栈.md
index 8d4db953..3723f4a7 100644
--- a/problems/0225.用队列实现栈.md
+++ b/problems/0225.用队列实现栈.md
@@ -538,4 +538,4 @@ MyStack.prototype.empty = function() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0226.翻转二叉树.md b/problems/0226.翻转二叉树.md
index fb5d831a..157ee05c 100644
--- a/problems/0226.翻转二叉树.md
+++ b/problems/0226.翻转二叉树.md
@@ -569,4 +569,4 @@ var invertTree = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0232.用栈实现队列.md b/problems/0232.用栈实现队列.md
index 9f6bb90f..ba12e0ab 100644
--- a/problems/0232.用栈实现队列.md
+++ b/problems/0232.用栈实现队列.md
@@ -356,4 +356,4 @@ MyQueue.prototype.empty = function() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0234.回文链表.md b/problems/0234.回文链表.md
index 631d2f6b..eada4474 100644
--- a/problems/0234.回文链表.md
+++ b/problems/0234.回文链表.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 234.回文链表
[力扣题目链接](https://leetcode-cn.com/problems/palindrome-linked-list/)
@@ -288,9 +288,9 @@ class Solution:
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0235.二叉搜索树的最近公共祖先.md b/problems/0235.二叉搜索树的最近公共祖先.md
index a828096c..1d36ce37 100644
--- a/problems/0235.二叉搜索树的最近公共祖先.md
+++ b/problems/0235.二叉搜索树的最近公共祖先.md
@@ -357,4 +357,4 @@ var lowestCommonAncestor = function(root, p, q) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0236.二叉树的最近公共祖先.md b/problems/0236.二叉树的最近公共祖先.md
index 46dcb545..215cb021 100644
--- a/problems/0236.二叉树的最近公共祖先.md
+++ b/problems/0236.二叉树的最近公共祖先.md
@@ -345,4 +345,4 @@ var lowestCommonAncestor = function(root, p, q) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0239.滑动窗口最大值.md b/problems/0239.滑动窗口最大值.md
index a61e4ca8..48c65837 100644
--- a/problems/0239.滑动窗口最大值.md
+++ b/problems/0239.滑动窗口最大值.md
@@ -425,4 +425,4 @@ var maxSlidingWindow = function (nums, k) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md
index 0828d360..c6981587 100644
--- a/problems/0242.有效的字母异位词.md
+++ b/problems/0242.有效的字母异位词.md
@@ -286,4 +286,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md
index e8a98527..7438f924 100644
--- a/problems/0257.二叉树的所有路径.md
+++ b/problems/0257.二叉树的所有路径.md
@@ -516,4 +516,4 @@ var binaryTreePaths = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0279.完全平方数.md b/problems/0279.完全平方数.md
index 865669c2..ca7c4966 100644
--- a/problems/0279.完全平方数.md
+++ b/problems/0279.完全平方数.md
@@ -361,4 +361,4 @@ var numSquares2 = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0283.移动零.md b/problems/0283.移动零.md
index 3909bcd5..18b29c3f 100644
--- a/problems/0283.移动零.md
+++ b/problems/0283.移动零.md
@@ -1,4 +1,3 @@
-
@@ -6,6 +5,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 动态规划:一样的套路,再求一次完全平方数
# 283. 移动零
@@ -96,9 +96,9 @@ Go:
JavaScript:
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0300.最长上升子序列.md b/problems/0300.最长上升子序列.md
index fdd5fda8..fe88ef26 100644
--- a/problems/0300.最长上升子序列.md
+++ b/problems/0300.最长上升子序列.md
@@ -202,4 +202,4 @@ const lengthOfLIS = (nums) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0309.最佳买卖股票时机含冷冻期.md b/problems/0309.最佳买卖股票时机含冷冻期.md
index 1bb38568..47da9584 100644
--- a/problems/0309.最佳买卖股票时机含冷冻期.md
+++ b/problems/0309.最佳买卖股票时机含冷冻期.md
@@ -237,4 +237,4 @@ const maxProfit = (prices) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0322.零钱兑换.md b/problems/0322.零钱兑换.md
index cdc5027c..8e03b391 100644
--- a/problems/0322.零钱兑换.md
+++ b/problems/0322.零钱兑换.md
@@ -330,4 +330,4 @@ const coinChange = (coins, amount) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0332.重新安排行程.md b/problems/0332.重新安排行程.md
index 13ad9e35..6f993e3e 100644
--- a/problems/0332.重新安排行程.md
+++ b/problems/0332.重新安排行程.md
@@ -450,4 +450,4 @@ var findItinerary = function(tickets) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0337.打家劫舍III.md b/problems/0337.打家劫舍III.md
index dfb8ba57..f65bcdb6 100644
--- a/problems/0337.打家劫舍III.md
+++ b/problems/0337.打家劫舍III.md
@@ -402,4 +402,4 @@ const rob = root => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0343.整数拆分.md b/problems/0343.整数拆分.md
index c11210fc..1f025051 100644
--- a/problems/0343.整数拆分.md
+++ b/problems/0343.整数拆分.md
@@ -276,4 +276,4 @@ var integerBreak = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md
index a02c27d5..8dc0e082 100644
--- a/problems/0344.反转字符串.md
+++ b/problems/0344.反转字符串.md
@@ -233,4 +233,4 @@ func reverseString(_ s: inout [Character]) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0347.前K个高频元素.md b/problems/0347.前K个高频元素.md
index 6012e118..315c184b 100644
--- a/problems/0347.前K个高频元素.md
+++ b/problems/0347.前K个高频元素.md
@@ -364,4 +364,4 @@ PriorityQueue.prototype.compare = function(index1, index2) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md
index 203d9b6f..8c170ed9 100644
--- a/problems/0349.两个数组的交集.md
+++ b/problems/0349.两个数组的交集.md
@@ -266,4 +266,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md
index 75965c37..74a75ef1 100644
--- a/problems/0376.摆动序列.md
+++ b/problems/0376.摆动序列.md
@@ -192,4 +192,4 @@ var wiggleMaxLength = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md
index 01f48d45..81e9dee3 100644
--- a/problems/0377.组合总和Ⅳ.md
+++ b/problems/0377.组合总和Ⅳ.md
@@ -246,4 +246,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md
index 75b31698..ac851fcd 100644
--- a/problems/0383.赎金信.md
+++ b/problems/0383.赎金信.md
@@ -342,4 +342,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0392.判断子序列.md b/problems/0392.判断子序列.md
index 784e3bbc..43cfbe7e 100644
--- a/problems/0392.判断子序列.md
+++ b/problems/0392.判断子序列.md
@@ -231,4 +231,4 @@ func isSubsequence(s string, t string) bool {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md
index c0eb7c8e..1fac7c9b 100644
--- a/problems/0404.左叶子之和.md
+++ b/problems/0404.左叶子之和.md
@@ -382,4 +382,4 @@ var sumOfLeftLeaves = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md
index 3c6ee63c..91e10cd5 100644
--- a/problems/0406.根据身高重建队列.md
+++ b/problems/0406.根据身高重建队列.md
@@ -297,4 +297,4 @@ var reconstructQueue = function(people) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0416.分割等和子集.md b/problems/0416.分割等和子集.md
index 415ff88b..60695d1e 100644
--- a/problems/0416.分割等和子集.md
+++ b/problems/0416.分割等和子集.md
@@ -293,4 +293,4 @@ var canPartition = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md
index 4e850114..282404d8 100644
--- a/problems/0435.无重叠区间.md
+++ b/problems/0435.无重叠区间.md
@@ -319,4 +319,4 @@ var eraseOverlapIntervals = function(intervals) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0450.删除二叉搜索树中的节点.md b/problems/0450.删除二叉搜索树中的节点.md
index f5133b84..6fa7fa2d 100644
--- a/problems/0450.删除二叉搜索树中的节点.md
+++ b/problems/0450.删除二叉搜索树中的节点.md
@@ -491,4 +491,4 @@ var deleteNode = function (root, key) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0452.用最少数量的箭引爆气球.md b/problems/0452.用最少数量的箭引爆气球.md
index 07141558..75ad01e8 100644
--- a/problems/0452.用最少数量的箭引爆气球.md
+++ b/problems/0452.用最少数量的箭引爆气球.md
@@ -247,4 +247,4 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md
index 43b4070f..4f030268 100644
--- a/problems/0454.四数相加II.md
+++ b/problems/0454.四数相加II.md
@@ -286,4 +286,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md
index bae1566c..41f04600 100644
--- a/problems/0455.分发饼干.md
+++ b/problems/0455.分发饼干.md
@@ -245,4 +245,4 @@ int findContentChildren(int* g, int gSize, int* s, int sSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md
index 7d8a7286..6d9b8d9f 100644
--- a/problems/0459.重复的子字符串.md
+++ b/problems/0459.重复的子字符串.md
@@ -369,4 +369,4 @@ var repeatedSubstringPattern = function (s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0463.岛屿的周长.md b/problems/0463.岛屿的周长.md
index fd9585d2..511f85d9 100644
--- a/problems/0463.岛屿的周长.md
+++ b/problems/0463.岛屿的周长.md
@@ -1,3 +1,10 @@
+
+
+
+
+
+
+欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
# 463. 岛屿的周长
[力扣题目链接](https://leetcode-cn.com/problems/island-perimeter/)
@@ -126,4 +133,4 @@ JavaScript:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0474.一和零.md b/problems/0474.一和零.md
index 5544c3c9..108a5ee3 100644
--- a/problems/0474.一和零.md
+++ b/problems/0474.一和零.md
@@ -331,4 +331,4 @@ const findMaxForm = (strs, m, n) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md
index d3dc3472..63a2b8d5 100644
--- a/problems/0491.递增子序列.md
+++ b/problems/0491.递增子序列.md
@@ -320,4 +320,4 @@ var findSubsequences = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0494.目标和.md b/problems/0494.目标和.md
index c24ce6f9..a2388edf 100644
--- a/problems/0494.目标和.md
+++ b/problems/0494.目标和.md
@@ -392,4 +392,4 @@ const findTargetSumWays = (nums, target) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0496.下一个更大元素I.md b/problems/0496.下一个更大元素I.md
index 45824d82..d7fd1d94 100644
--- a/problems/0496.下一个更大元素I.md
+++ b/problems/0496.下一个更大元素I.md
@@ -1,3 +1,10 @@
+
+
+
+
+
+
+欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
# 496.下一个更大元素 I
@@ -294,4 +301,8 @@ var nextGreaterElement = function (nums1, nums2) {
};
```
-
+-----------------------
+* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
+* B站视频:[代码随想录](https://space.bilibili.com/525438321)
+* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
+
diff --git a/problems/0501.二叉搜索树中的众数.md b/problems/0501.二叉搜索树中的众数.md
index 22d4f4ac..1d24367e 100644
--- a/problems/0501.二叉搜索树中的众数.md
+++ b/problems/0501.二叉搜索树中的众数.md
@@ -690,4 +690,4 @@ var findMode = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0503.下一个更大元素II.md b/problems/0503.下一个更大元素II.md
index 624c6c7c..13adc024 100644
--- a/problems/0503.下一个更大元素II.md
+++ b/problems/0503.下一个更大元素II.md
@@ -1,3 +1,10 @@
+
+
+
+
+
+
+欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
# 503.下一个更大元素II
@@ -178,4 +185,8 @@ var nextGreaterElements = function (nums) {
return res;
};
```
-
+-----------------------
+* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
+* B站视频:[代码随想录](https://space.bilibili.com/525438321)
+* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
+
diff --git a/problems/0509.斐波那契数.md b/problems/0509.斐波那契数.md
index 7e4df26c..86591157 100644
--- a/problems/0509.斐波那契数.md
+++ b/problems/0509.斐波那契数.md
@@ -238,4 +238,4 @@ var fib = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0513.找树左下角的值.md b/problems/0513.找树左下角的值.md
index d2c05fd8..ef44f700 100644
--- a/problems/0513.找树左下角的值.md
+++ b/problems/0513.找树左下角的值.md
@@ -441,4 +441,4 @@ var findBottomLeftValue = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0516.最长回文子序列.md b/problems/0516.最长回文子序列.md
index 89b5667f..629e9247 100644
--- a/problems/0516.最长回文子序列.md
+++ b/problems/0516.最长回文子序列.md
@@ -243,4 +243,4 @@ const longestPalindromeSubseq = (s) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md
index 6eb31cd8..44c00131 100644
--- a/problems/0518.零钱兑换II.md
+++ b/problems/0518.零钱兑换II.md
@@ -266,4 +266,4 @@ const change = (amount, coins) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0530.二叉搜索树的最小绝对差.md b/problems/0530.二叉搜索树的最小绝对差.md
index b19a0dd2..e4467178 100644
--- a/problems/0530.二叉搜索树的最小绝对差.md
+++ b/problems/0530.二叉搜索树的最小绝对差.md
@@ -370,4 +370,4 @@ var getMinimumDifference = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0538.把二叉搜索树转换为累加树.md b/problems/0538.把二叉搜索树转换为累加树.md
index 24fc7211..baeb300f 100644
--- a/problems/0538.把二叉搜索树转换为累加树.md
+++ b/problems/0538.把二叉搜索树转换为累加树.md
@@ -277,4 +277,4 @@ var convertBST = function (root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0541.反转字符串II.md b/problems/0541.反转字符串II.md
index df2fade8..e6939c89 100644
--- a/problems/0541.反转字符串II.md
+++ b/problems/0541.反转字符串II.md
@@ -282,4 +282,4 @@ func reverseStr(_ s: String, _ k: Int) -> String {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0583.两个字符串的删除操作.md b/problems/0583.两个字符串的删除操作.md
index 079b2028..4935d10c 100644
--- a/problems/0583.两个字符串的删除操作.md
+++ b/problems/0583.两个字符串的删除操作.md
@@ -211,4 +211,4 @@ const minDistance = (word1, word2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0617.合并二叉树.md b/problems/0617.合并二叉树.md
index e21efcb3..71e2dbb2 100644
--- a/problems/0617.合并二叉树.md
+++ b/problems/0617.合并二叉树.md
@@ -541,4 +541,4 @@ var mergeTrees = function (root1, root2) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0647.回文子串.md b/problems/0647.回文子串.md
index 7b90ca0c..f2d0e7e5 100644
--- a/problems/0647.回文子串.md
+++ b/problems/0647.回文子串.md
@@ -412,4 +412,4 @@ const countSubstrings = (s) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0649.Dota2参议院.md b/problems/0649.Dota2参议院.md
index e2900824..b324df04 100644
--- a/problems/0649.Dota2参议院.md
+++ b/problems/0649.Dota2参议院.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 649. Dota2 参议院
[力扣题目链接](https://leetcode-cn.com/problems/dota2-senate/)
@@ -221,9 +221,9 @@ func predictPartyVictory(senateStr string) string {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0654.最大二叉树.md b/problems/0654.最大二叉树.md
index b644a0a3..aa84c8a6 100644
--- a/problems/0654.最大二叉树.md
+++ b/problems/0654.最大二叉树.md
@@ -362,4 +362,4 @@ var constructMaximumBinaryTree = function (nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0657.机器人能否返回原点.md b/problems/0657.机器人能否返回原点.md
index ffa5d6f2..4e48698e 100644
--- a/problems/0657.机器人能否返回原点.md
+++ b/problems/0657.机器人能否返回原点.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 657. 机器人能否返回原点
[力扣题目链接](https://leetcode-cn.com/problems/robot-return-to-origin/)
@@ -151,9 +151,9 @@ var judgeCircle = function(moves) {
};
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0669.修剪二叉搜索树.md b/problems/0669.修剪二叉搜索树.md
index ef6a3e00..ffb00b78 100644
--- a/problems/0669.修剪二叉搜索树.md
+++ b/problems/0669.修剪二叉搜索树.md
@@ -395,4 +395,4 @@ var trimBST = function (root,low,high) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0673.最长递增子序列的个数.md b/problems/0673.最长递增子序列的个数.md
index 653edadf..d18ef2e6 100644
--- a/problems/0673.最长递增子序列的个数.md
+++ b/problems/0673.最长递增子序列的个数.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 673.最长递增子序列的个数
@@ -339,9 +339,9 @@ func findNumberOfLIS(nums []int) int {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md
index 3f3b5e6f..383f770e 100644
--- a/problems/0674.最长连续递增序列.md
+++ b/problems/0674.最长连续递增序列.md
@@ -268,4 +268,4 @@ const findLengthOfLCIS = (nums) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0684.冗余连接.md b/problems/0684.冗余连接.md
index bfbdeba9..a0155c18 100644
--- a/problems/0684.冗余连接.md
+++ b/problems/0684.冗余连接.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 684.冗余连接
@@ -305,15 +305,15 @@ func findRedundantConnection(edges [][]int) []int {
```js
```
+
+
+
+
+
+
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
-
-
-
-
-
+
diff --git a/problems/0685.冗余连接II.md b/problems/0685.冗余连接II.md
index 404813f3..1f01794d 100644
--- a/problems/0685.冗余连接II.md
+++ b/problems/0685.冗余连接II.md
@@ -1,5 +1,3 @@
-
-
@@ -517,10 +515,10 @@ func findRedundantDirectedConnection(edges [][]int) []int {
```js
```
+
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
+
diff --git a/problems/0700.二叉搜索树中的搜索.md b/problems/0700.二叉搜索树中的搜索.md
index c25ea12f..e4227eb1 100644
--- a/problems/0700.二叉搜索树中的搜索.md
+++ b/problems/0700.二叉搜索树中的搜索.md
@@ -342,4 +342,4 @@ var searchBST = function (root, val) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0701.二叉搜索树中的插入操作.md b/problems/0701.二叉搜索树中的插入操作.md
index d5b9eb3f..33e9999c 100644
--- a/problems/0701.二叉搜索树中的插入操作.md
+++ b/problems/0701.二叉搜索树中的插入操作.md
@@ -492,4 +492,4 @@ var insertIntoBST = function (root, val) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md
index 67809000..dc9f2e74 100644
--- a/problems/0704.二分查找.md
+++ b/problems/0704.二分查找.md
@@ -529,4 +529,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0707.设计链表.md b/problems/0707.设计链表.md
index e05165a9..077b0e87 100644
--- a/problems/0707.设计链表.md
+++ b/problems/0707.设计链表.md
@@ -1037,4 +1037,4 @@ class MyLinkedList {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0714.买卖股票的最佳时机含手续费.md b/problems/0714.买卖股票的最佳时机含手续费.md
index 4ac4684e..cdedd506 100644
--- a/problems/0714.买卖股票的最佳时机含手续费.md
+++ b/problems/0714.买卖股票的最佳时机含手续费.md
@@ -269,4 +269,4 @@ var maxProfit = function(prices, fee) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
index 7c54a2fe..d1dfeb91 100644
--- a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
+++ b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
@@ -190,4 +190,4 @@ const maxProfit = (prices,fee) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0718.最长重复子数组.md b/problems/0718.最长重复子数组.md
index 712b5eeb..d3488a06 100644
--- a/problems/0718.最长重复子数组.md
+++ b/problems/0718.最长重复子数组.md
@@ -304,4 +304,4 @@ const findLength = (nums1, nums2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0724.寻找数组的中心索引.md b/problems/0724.寻找数组的中心索引.md
index 991ce647..7aef5094 100644
--- a/problems/0724.寻找数组的中心索引.md
+++ b/problems/0724.寻找数组的中心索引.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 724.寻找数组的中心下标
[力扣题目链接](https://leetcode-cn.com/problems/find-pivot-index/)
@@ -131,9 +131,9 @@ func pivotIndex(nums []int) int {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md
index f63a05b8..70c571db 100644
--- a/problems/0738.单调递增的数字.md
+++ b/problems/0738.单调递增的数字.md
@@ -209,4 +209,4 @@ var monotoneIncreasingDigits = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md
index 53ce1133..5e570307 100644
--- a/problems/0739.每日温度.md
+++ b/problems/0739.每日温度.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 739. 每日温度
[力扣题目链接](https://leetcode-cn.com/problems/daily-temperatures/)
@@ -308,9 +308,9 @@ var dailyTemperatures = function(temperatures) {
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md
index eb2a437a..9e1a430e 100644
--- a/problems/0746.使用最小花费爬楼梯.md
+++ b/problems/0746.使用最小花费爬楼梯.md
@@ -272,4 +272,4 @@ var minCostClimbingStairs = function(cost) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md
index 43c663c2..bb327db2 100644
--- a/problems/0763.划分字母区间.md
+++ b/problems/0763.划分字母区间.md
@@ -181,4 +181,4 @@ var partitionLabels = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0841.钥匙和房间.md b/problems/0841.钥匙和房间.md
index d281dc5a..668191b4 100644
--- a/problems/0841.钥匙和房间.md
+++ b/problems/0841.钥匙和房间.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 841.钥匙和房间
[力扣题目链接](https://leetcode-cn.com/problems/keys-and-rooms/)
@@ -221,9 +221,9 @@ func canVisitAllRooms(rooms [][]int) bool {
JavaScript:
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0844.比较含退格的字符串.md b/problems/0844.比较含退格的字符串.md
index 74455ace..ae21404e 100644
--- a/problems/0844.比较含退格的字符串.md
+++ b/problems/0844.比较含退格的字符串.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 844.比较含退格的字符串
[力扣题目链接](https://leetcode-cn.com/problems/backspace-string-compare/)
@@ -233,9 +233,9 @@ func backspaceCompare(s string, t string) bool {
JavaScript:
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md
index 46e05419..91a1450d 100644
--- a/problems/0860.柠檬水找零.md
+++ b/problems/0860.柠檬水找零.md
@@ -260,4 +260,4 @@ var lemonadeChange = function(bills) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0922.按奇偶排序数组II.md b/problems/0922.按奇偶排序数组II.md
index 5b66247e..beb063b0 100644
--- a/problems/0922.按奇偶排序数组II.md
+++ b/problems/0922.按奇偶排序数组II.md
@@ -1,4 +1,3 @@
-
@@ -9,6 +8,7 @@
+
# 922. 按奇偶排序数组II
[力扣题目链接](https://leetcode-cn.com/problems/sort-array-by-parity-ii/)
@@ -211,9 +211,9 @@ func sortArrayByParityII(nums []int) []int {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0925.长按键入.md b/problems/0925.长按键入.md
index 70597508..0a10c1b3 100644
--- a/problems/0925.长按键入.md
+++ b/problems/0925.长按键入.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 925.长按键入
[力扣题目链接](https://leetcode-cn.com/problems/long-pressed-name/)
@@ -183,9 +183,9 @@ func isLongPressedName(name string, typed string) bool {
JavaScript:
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/0941.有效的山脉数组.md b/problems/0941.有效的山脉数组.md
index c4c8ebfa..14c13edd 100644
--- a/problems/0941.有效的山脉数组.md
+++ b/problems/0941.有效的山脉数组.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 941.有效的山脉数组
[力扣题目链接](https://leetcode-cn.com/problems/valid-mountain-array/)
@@ -156,11 +156,11 @@ func validMountainArray(arr []int) bool {
```js
```
+
+
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
-
+
diff --git a/problems/0968.监控二叉树.md b/problems/0968.监控二叉树.md
index 384c9a78..579b38ab 100644
--- a/problems/0968.监控二叉树.md
+++ b/problems/0968.监控二叉树.md
@@ -510,4 +510,4 @@ int minCameraCover(struct TreeNode* root){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md
index a57af3c1..12b413e1 100644
--- a/problems/0977.有序数组的平方.md
+++ b/problems/0977.有序数组的平方.md
@@ -339,4 +339,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md
index e02780da..7a9677ad 100644
--- a/problems/1002.查找常用字符.md
+++ b/problems/1002.查找常用字符.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 1002. 查找常用字符
[力扣题目链接](https://leetcode-cn.com/problems/find-common-characters/)
@@ -333,4 +333,4 @@ func commonChars(_ words: [String]) -> [String] {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1005.K次取反后最大化的数组和.md b/problems/1005.K次取反后最大化的数组和.md
index 020476a9..1d552590 100644
--- a/problems/1005.K次取反后最大化的数组和.md
+++ b/problems/1005.K次取反后最大化的数组和.md
@@ -217,4 +217,4 @@ var largestSumAfterKNegations = function(nums, k) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md
index a10fd381..04f8de09 100644
--- a/problems/1035.不相交的线.md
+++ b/problems/1035.不相交的线.md
@@ -139,4 +139,4 @@ const maxUncrossedLines = (nums1, nums2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1047.删除字符串中的所有相邻重复项.md b/problems/1047.删除字符串中的所有相邻重复项.md
index b88fd618..420b64df 100644
--- a/problems/1047.删除字符串中的所有相邻重复项.md
+++ b/problems/1047.删除字符串中的所有相邻重复项.md
@@ -275,4 +275,4 @@ var removeDuplicates = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1049.最后一块石头的重量II.md b/problems/1049.最后一块石头的重量II.md
index 795d923c..390e8c70 100644
--- a/problems/1049.最后一块石头的重量II.md
+++ b/problems/1049.最后一块石头的重量II.md
@@ -246,4 +246,4 @@ var lastStoneWeightII = function (stones) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1143.最长公共子序列.md b/problems/1143.最长公共子序列.md
index b3b5e6c0..005d333a 100644
--- a/problems/1143.最长公共子序列.md
+++ b/problems/1143.最长公共子序列.md
@@ -221,4 +221,4 @@ const longestCommonSubsequence = (text1, text2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md
index 027c9f5a..5b622546 100644
--- a/problems/1207.独一无二的出现次数.md
+++ b/problems/1207.独一无二的出现次数.md
@@ -119,9 +119,9 @@ Go:
JavaScript:
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/1221.分割平衡字符串.md b/problems/1221.分割平衡字符串.md
index c764e3ff..e5652623 100644
--- a/problems/1221.分割平衡字符串.md
+++ b/problems/1221.分割平衡字符串.md
@@ -110,9 +110,9 @@ public:
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/1356.根据数字二进制下1的数目排序.md b/problems/1356.根据数字二进制下1的数目排序.md
index 06c29500..3c87b10d 100644
--- a/problems/1356.根据数字二进制下1的数目排序.md
+++ b/problems/1356.根据数字二进制下1的数目排序.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 1356. 根据数字二进制下 1 的数目排序
[力扣题目链接](https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits/)
@@ -168,9 +168,9 @@ class Solution {
```js
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/1365.有多少小于当前数字的数字.md b/problems/1365.有多少小于当前数字的数字.md
index 5cf6b2d8..4c0b4d58 100644
--- a/problems/1365.有多少小于当前数字的数字.md
+++ b/problems/1365.有多少小于当前数字的数字.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 1365.有多少小于当前数字的数字
[力扣题目链接](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/)
@@ -162,4 +162,4 @@ JavaScript:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1382.将二叉搜索树变平衡.md b/problems/1382.将二叉搜索树变平衡.md
index bce58c33..c1a8f69e 100644
--- a/problems/1382.将二叉搜索树变平衡.md
+++ b/problems/1382.将二叉搜索树变平衡.md
@@ -1,4 +1,3 @@
-
@@ -7,6 +6,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
# 1382.将二叉搜索树变平衡
[力扣题目链接](https://leetcode-cn.com/problems/balance-a-binary-search-tree/)
@@ -127,10 +127,10 @@ Go:
JavaScript:
+
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
-
+
diff --git a/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md b/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md
index 6897c01f..e7a316fb 100644
--- a/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md
+++ b/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md
@@ -235,4 +235,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md b/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md
index 2eb253ba..08841565 100644
--- a/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md
+++ b/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md
@@ -207,4 +207,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树中递归带着回溯.md b/problems/二叉树中递归带着回溯.md
index 7b0ccad7..e097a2dd 100644
--- a/problems/二叉树中递归带着回溯.md
+++ b/problems/二叉树中递归带着回溯.md
@@ -448,4 +448,4 @@ func traversal(root *TreeNode,result *[]string,path *[]int){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树总结篇.md b/problems/二叉树总结篇.md
index ee046366..9563acf6 100644
--- a/problems/二叉树总结篇.md
+++ b/problems/二叉树总结篇.md
@@ -175,4 +175,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树理论基础.md b/problems/二叉树理论基础.md
index b25f3be1..c7b316b3 100644
--- a/problems/二叉树理论基础.md
+++ b/problems/二叉树理论基础.md
@@ -234,4 +234,4 @@ function TreeNode(val, left, right) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树的统一迭代法.md b/problems/二叉树的统一迭代法.md
index d8299e10..3fa73851 100644
--- a/problems/二叉树的统一迭代法.md
+++ b/problems/二叉树的统一迭代法.md
@@ -530,4 +530,4 @@ var postorderTraversal = function(root, res = []) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md
index 84363610..ae0bc98d 100644
--- a/problems/二叉树的迭代遍历.md
+++ b/problems/二叉树的迭代遍历.md
@@ -473,4 +473,4 @@ var postorderTraversal = function(root, res = []) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树的递归遍历.md b/problems/二叉树的递归遍历.md
index 93f4000e..06d0d39e 100644
--- a/problems/二叉树的递归遍历.md
+++ b/problems/二叉树的递归遍历.md
@@ -415,4 +415,4 @@ int* postorderTraversal(struct TreeNode* root, int* returnSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/关于时间复杂度,你不知道的都在这里!.md b/problems/关于时间复杂度,你不知道的都在这里!.md
index 7ff9b470..94f4bd1d 100644
--- a/problems/关于时间复杂度,你不知道的都在这里!.md
+++ b/problems/关于时间复杂度,你不知道的都在这里!.md
@@ -177,4 +177,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/剑指Offer05.替换空格.md b/problems/剑指Offer05.替换空格.md
index 47907319..86d6baf8 100644
--- a/problems/剑指Offer05.替换空格.md
+++ b/problems/剑指Offer05.替换空格.md
@@ -313,4 +313,4 @@ func replaceSpace(_ s: String) -> String {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/剑指Offer58-II.左旋转字符串.md b/problems/剑指Offer58-II.左旋转字符串.md
index d8aaca67..3767c6dd 100644
--- a/problems/剑指Offer58-II.左旋转字符串.md
+++ b/problems/剑指Offer58-II.左旋转字符串.md
@@ -249,4 +249,4 @@ func reverseString(_ s: inout [Character], startIndex: Int, endIndex: Int) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/动态规划-股票问题总结篇.md b/problems/动态规划-股票问题总结篇.md
index a3443ecb..b2a3e8da 100644
--- a/problems/动态规划-股票问题总结篇.md
+++ b/problems/动态规划-股票问题总结篇.md
@@ -486,4 +486,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/动态规划总结篇.md b/problems/动态规划总结篇.md
index e7e57351..512fad08 100644
--- a/problems/动态规划总结篇.md
+++ b/problems/动态规划总结篇.md
@@ -1,4 +1,3 @@
-
@@ -8,6 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+
如今动态规划已经讲解了42道经典题目,共50篇文章,是时候做一篇总结了。
关于动态规划,在专题第一篇[关于动态规划,你该了解这些!](https://programmercarl.com/动态规划理论基础.html)就说了动规五部曲,**而且强调了五部对解动规题目至关重要!**
@@ -132,9 +132,9 @@
最后感谢录友们的一路支持,Carl才有继续更下去的动力[玫瑰],[撒花]
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
-
+
diff --git a/problems/动态规划理论基础.md b/problems/动态规划理论基础.md
index bd46586f..7a7a304b 100644
--- a/problems/动态规划理论基础.md
+++ b/problems/动态规划理论基础.md
@@ -132,4 +132,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/双指针总结.md b/problems/双指针总结.md
index 11d6ffa4..f5e7ba67 100644
--- a/problems/双指针总结.md
+++ b/problems/双指针总结.md
@@ -100,4 +100,4 @@ for (int i = 0; i < array.size(); i++) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/哈希表总结.md b/problems/哈希表总结.md
index 58e386bc..71100bf6 100644
--- a/problems/哈希表总结.md
+++ b/problems/哈希表总结.md
@@ -131,4 +131,4 @@ std::unordered_map 底层实现为哈希,std::map 和std::multimap 的底层
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/哈希表理论基础.md b/problems/哈希表理论基础.md
index 2d3b03bd..331d26c8 100644
--- a/problems/哈希表理论基础.md
+++ b/problems/哈希表理论基础.md
@@ -133,4 +133,4 @@ std::unordered_map 底层实现为哈希表,std::map 和std::multimap 的底
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/回溯总结.md b/problems/回溯总结.md
index 5a9725dd..ebbcb073 100644
--- a/problems/回溯总结.md
+++ b/problems/回溯总结.md
@@ -454,4 +454,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/回溯算法去重问题的另一种写法.md b/problems/回溯算法去重问题的另一种写法.md
index d267d23c..cfc8ad86 100644
--- a/problems/回溯算法去重问题的另一种写法.md
+++ b/problems/回溯算法去重问题的另一种写法.md
@@ -263,4 +263,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/回溯算法理论基础.md b/problems/回溯算法理论基础.md
index c351ddba..286d0b77 100644
--- a/problems/回溯算法理论基础.md
+++ b/problems/回溯算法理论基础.md
@@ -175,4 +175,4 @@ void backtracking(参数) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/字符串总结.md b/problems/字符串总结.md
index 57ac9a31..258ea0ef 100644
--- a/problems/字符串总结.md
+++ b/problems/字符串总结.md
@@ -130,4 +130,4 @@ KMP算法是字符串查找最重要的算法,但彻底理解KMP并不容易
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/数组总结篇.md b/problems/数组总结篇.md
index 7fafb94b..0bf90c66 100644
--- a/problems/数组总结篇.md
+++ b/problems/数组总结篇.md
@@ -149,4 +149,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/数组理论基础.md b/problems/数组理论基础.md
index 146cd2de..b53665ee 100644
--- a/problems/数组理论基础.md
+++ b/problems/数组理论基础.md
@@ -124,4 +124,4 @@ public static void test_arr() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/栈与队列总结.md b/problems/栈与队列总结.md
index ffcd38a1..db8e1296 100644
--- a/problems/栈与队列总结.md
+++ b/problems/栈与队列总结.md
@@ -181,4 +181,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/栈与队列理论基础.md b/problems/栈与队列理论基础.md
index c43ce0f5..8c2effec 100644
--- a/problems/栈与队列理论基础.md
+++ b/problems/栈与队列理论基础.md
@@ -94,4 +94,4 @@ std::queue> third; // 定义以list为底层容器的队列
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/根据身高重建队列(vector原理讲解).md b/problems/根据身高重建队列(vector原理讲解).md
index dfc824fa..143ee01f 100644
--- a/problems/根据身高重建队列(vector原理讲解).md
+++ b/problems/根据身高重建队列(vector原理讲解).md
@@ -180,4 +180,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/算法模板.md b/problems/算法模板.md
index b56678ab..0cf8431d 100644
--- a/problems/算法模板.md
+++ b/problems/算法模板.md
@@ -296,4 +296,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包总结篇.md b/problems/背包总结篇.md
index f3732c8d..6086274e 100644
--- a/problems/背包总结篇.md
+++ b/problems/背包总结篇.md
@@ -101,4 +101,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包理论基础01背包-1.md b/problems/背包理论基础01背包-1.md
index 030c00d2..b2cee391 100644
--- a/problems/背包理论基础01背包-1.md
+++ b/problems/背包理论基础01背包-1.md
@@ -431,4 +431,4 @@ test();
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包理论基础01背包-2.md b/problems/背包理论基础01背包-2.md
index 07f74186..ac551565 100644
--- a/problems/背包理论基础01背包-2.md
+++ b/problems/背包理论基础01背包-2.md
@@ -323,4 +323,4 @@ test();
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包问题理论基础多重背包.md b/problems/背包问题理论基础多重背包.md
index a2ef88a4..814c9711 100644
--- a/problems/背包问题理论基础多重背包.md
+++ b/problems/背包问题理论基础多重背包.md
@@ -209,4 +209,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包问题理论基础完全背包.md b/problems/背包问题理论基础完全背包.md
index 455a3c33..4f3ef9ba 100644
--- a/problems/背包问题理论基础完全背包.md
+++ b/problems/背包问题理论基础完全背包.md
@@ -349,4 +349,4 @@ function test_completePack2() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/贪心算法总结篇.md b/problems/贪心算法总结篇.md
index 94e292ba..a203494e 100644
--- a/problems/贪心算法总结篇.md
+++ b/problems/贪心算法总结篇.md
@@ -158,4 +158,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/贪心算法理论基础.md b/problems/贪心算法理论基础.md
index 9c131709..495348d0 100644
--- a/problems/贪心算法理论基础.md
+++ b/problems/贪心算法理论基础.md
@@ -94,4 +94,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/链表总结篇.md b/problems/链表总结篇.md
index fed8cb60..64a7b42a 100644
--- a/problems/链表总结篇.md
+++ b/problems/链表总结篇.md
@@ -98,4 +98,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/链表理论基础.md b/problems/链表理论基础.md
index d210b6bd..7e0cd431 100644
--- a/problems/链表理论基础.md
+++ b/problems/链表理论基础.md
@@ -159,4 +159,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/面试题02.07.链表相交.md b/problems/面试题02.07.链表相交.md
index d59256c6..d694899d 100644
--- a/problems/面试题02.07.链表相交.md
+++ b/problems/面试题02.07.链表相交.md
@@ -258,4 +258,4 @@ var getIntersectionNode = function(headA, headB) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
From eb87eb0b321e13619dd72f8a8de8f64fa96a7a8f Mon Sep 17 00:00:00 2001
From: baichangfu
Date: Wed, 29 Sep 2021 11:19:48 +0800
Subject: [PATCH 177/284] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AC=94=E8=AF=AF=
=?UTF-8?q?=E6=95=B0=E7=BB=84=E6=80=BB=E7=BB=93=E7=AF=87>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/数组总结篇.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/problems/数组总结篇.md b/problems/数组总结篇.md
index 0bf90c66..528904c2 100644
--- a/problems/数组总结篇.md
+++ b/problems/数组总结篇.md
@@ -51,7 +51,7 @@
-所以**二维数据在内存中不是 `3*4` 的连续地址空间,而是四条连续的地址空间组成!**
+所以**二维数据在内存中不是 `3*4` 的连续地址空间,而是三条连续的地址空间组成!**
# 数组的经典题目
@@ -65,9 +65,9 @@
[数组:每次遇到二分法,都是一看就会,一写就废](https://programmercarl.com/0704.二分查找.html)
-这道题目呢,考察的数据的基本操作,思路很简单,但是在通过率在简单题里并不高,不要轻敌。
+这道题目呢,考察数组的基本操作,思路很简单,但是通过率在简单题里并不高,不要轻敌。
-可以使用暴力解法,通过这道题目,如果准求更优的算法,建议试一试用二分法,来解决这道题目
+可以使用暴力解法,通过这道题目,如果追求更优的算法,建议试一试用二分法,来解决这道题目
暴力解法时间复杂度:O(n)
二分法时间复杂度:O(logn)
@@ -86,10 +86,10 @@
暴力解法时间复杂度:O(n^2)
双指针时间复杂度:O(n)
-这道题目迷惑了不少同学,纠结于数组中的元素为什么不能删除,主要是因为一下两点:
+这道题目迷惑了不少同学,纠结于数组中的元素为什么不能删除,主要是因为以下两点:
* 数组在内存中是连续的地址空间,不能释放单一元素,如果要释放,就是全释放(程序运行结束,回收内存栈空间)。
-* C++中vector和array的区别一定要弄清楚,vector的底层实现是array,所以vector展现出友好的一些都是因为经过包装了。
+* C++中vector和array的区别一定要弄清楚,vector的底层实现是array,封装后使用更友好。
双指针法(快慢指针法)在数组和链表的操作中是非常常见的,很多考察数组和链表操作的面试题,都使用双指针法。
@@ -124,7 +124,7 @@
从二分法到双指针,从滑动窗口到螺旋矩阵,相信如果大家真的认真做了「代码随想录」每日推荐的题目,定会有所收获。
-推荐的题目即使大家之前做过了,再读一遍的文章,也会帮助你提炼出解题的精髓所在。
+推荐的题目即使大家之前做过了,再读一遍文章,也会帮助你提炼出解题的精髓所在。
如果感觉有所收获,希望大家多多支持,打卡转发,点赞在看 都是对我最大的鼓励!
From 5de0f0041f3367f7f7c5c8c6b8d57c39e7552617 Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Wed, 29 Sep 2021 11:28:47 +0800
Subject: [PATCH 178/284] Update
---
README.md | 1 +
problems/0001.两数之和.md | 2 +-
problems/0078.子集.md | 32 ++++++++++++++++----------------
3 files changed, 18 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index d1076aba..6a64da9f 100644
--- a/README.md
+++ b/README.md
@@ -458,6 +458,7 @@
* [724.寻找数组的中心索引](./problems/0724.寻找数组的中心索引.md)
* [34.在排序数组中查找元素的第一个和最后一个位置](./problems/0034.在排序数组中查找元素的第一个和最后一个位置.md) (二分法)
* [922.按奇偶排序数组II](./problems/0922.按奇偶排序数组II.md)
+* [35.搜索插入位置](./problems/0035.搜索插入位置.md)
## 链表
diff --git a/problems/0001.两数之和.md b/problems/0001.两数之和.md
index 0ef73c6a..949e52a7 100644
--- a/problems/0001.两数之和.md
+++ b/problems/0001.两数之和.md
@@ -253,4 +253,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0078.子集.md b/problems/0078.子集.md
index 39f6ed5d..59f291d0 100644
--- a/problems/0078.子集.md
+++ b/problems/0078.子集.md
@@ -7,7 +7,7 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
-## 第78题. 子集
+# 78.子集
[力扣题目链接](https://leetcode-cn.com/problems/subsets/)
@@ -29,7 +29,7 @@
[]
]
-## 思路
+# 思路
求子集问题和[77.组合](https://programmercarl.com/0077.组合.html)和[131.分割回文串](https://programmercarl.com/0131.分割回文串.html)又不一样了。
@@ -153,19 +153,19 @@ public:
并不会,因为每次递归的下一层就是从i+1开始的。
-## 总结
+# 总结
相信大家经过了
* 组合问题:
- * [回溯算法:求组合问题](https://programmercarl.com/0077.组合.html)
+ * [77.组合](https://programmercarl.com/0077.组合.html)
* [回溯算法:组合问题再剪剪枝](https://programmercarl.com/0077.组合优化.html)
- * [回溯算法:求组合总和!](https://programmercarl.com/0216.组合总和III.html)
- * [回溯算法:电话号码的字母组合](https://programmercarl.com/0017.电话号码的字母组合.html)
- * [回溯算法:求组合总和(二)](https://programmercarl.com/0039.组合总和.html)
- * [回溯算法:求组合总和(三)](https://programmercarl.com/0040.组合总和II.html)
+ * [216.组合总和III](https://programmercarl.com/0216.组合总和III.html)
+ * [17.电话号码的字母组合](https://programmercarl.com/0017.电话号码的字母组合.html)
+ * [39.组合总和](https://programmercarl.com/0039.组合总和.html)
+ * [40.组合总和II](https://programmercarl.com/0040.组合总和II.html)
* 分割问题:
- * [回溯算法:分割回文串](https://programmercarl.com/0131.分割回文串.html)
- * [回溯算法:复原IP地址](https://programmercarl.com/0093.复原IP地址.html)
+ * [131.分割回文串](https://programmercarl.com/0131.分割回文串.html)
+ * [93.复原IP地址](https://programmercarl.com/0093.复原IP地址.html)
洗礼之后,发现子集问题还真的有点简单了,其实这就是一道标准的模板题。
@@ -173,10 +173,10 @@ public:
**而组合问题、分割问题是收集树形结构中叶子节点的结果**。
-## 其他语言版本
+# 其他语言版本
-Java:
+## Java
```java
class Solution {
List> result = new ArrayList<>();// 存放符合条件结果的集合
@@ -204,7 +204,7 @@ class Solution {
}
```
-Python:
+## Python
```python3
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
@@ -220,7 +220,7 @@ class Solution:
return res
```
-Go:
+## Go
```Go
var res [][]int
func subset(nums []int) [][]int {
@@ -244,7 +244,7 @@ func Dfs(temp, nums []int, start int){
}
```
-Javascript:
+## Javascript:
```Javascript
var subsets = function(nums) {
@@ -263,7 +263,7 @@ var subsets = function(nums) {
};
```
-C:
+## C
```c
int* path;
int pathTop;
From 947cc4fad89e94810136a96ab0bc9e20781e96eb Mon Sep 17 00:00:00 2001
From: baichangfu
Date: Wed, 29 Sep 2021 11:47:15 +0800
Subject: [PATCH 179/284] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AC=94=E8=AF=AF=
=?UTF-8?q?=E9=93=BE=E8=A1=A8=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/链表理论基础.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/problems/链表理论基础.md b/problems/链表理论基础.md
index 7e0cd431..c62e4b82 100644
--- a/problems/链表理论基础.md
+++ b/problems/链表理论基础.md
@@ -9,9 +9,9 @@
# 关于链表,你该了解这些!
-什么是链表,链表是一种通过指针串联在一起的线性结构,每一个节点是又两部分组成,一个是数据域一个是指针域(存放指向下一个节点的指针),最后一个节点的指针域指向null(空指针的意思)。
+什么是链表,链表是一种通过指针串联在一起的线性结构,每一个节点由两部分组成,一个是数据域一个是指针域(存放指向下一个节点的指针),最后一个节点的指针域指向null(空指针的意思)。
-链接的入口点称为列表的头结点也就是head。
+链接的入口节点称为链表的头结点也就是head。
如图所示:

From 33768a0ffbee5195832b1e09252e941d51aea3f0 Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Wed, 29 Sep 2021 11:48:39 +0800
Subject: [PATCH 180/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0005.最长回文子串.md | 2 +-
problems/0015.三数之和.md | 2 +-
problems/0017.电话号码的字母组合.md | 2 +-
problems/0018.四数之和.md | 2 +-
problems/0019.删除链表的倒数第N个节点.md | 2 +-
problems/0020.有效的括号.md | 2 +-
problems/0024.两两交换链表中的节点.md | 2 +-
problems/0027.移除元素.md | 2 +-
problems/0028.实现strStr.md | 2 +-
problems/0031.下一个排列.md | 2 +-
problems/0034.在排序数组中查找元素的第一个和最后一个位置.md | 2 +-
problems/0035.搜索插入位置.md | 2 +-
problems/0037.解数独.md | 2 +-
problems/0039.组合总和.md | 2 +-
problems/0040.组合总和II.md | 2 +-
problems/0042.接雨水.md | 2 +-
problems/0045.跳跃游戏II.md | 2 +-
problems/0046.全排列.md | 2 +-
problems/0047.全排列II.md | 2 +-
problems/0051.N皇后.md | 2 +-
problems/0052.N皇后II.md | 2 +-
problems/0053.最大子序和.md | 2 +-
problems/0053.最大子序和(动态规划).md | 2 +-
problems/0055.跳跃游戏.md | 2 +-
problems/0056.合并区间.md | 2 +-
problems/0059.螺旋矩阵II.md | 2 +-
problems/0062.不同路径.md | 2 +-
problems/0063.不同路径II.md | 2 +-
problems/0070.爬楼梯.md | 2 +-
problems/0070.爬楼梯完全背包版本.md | 2 +-
problems/0072.编辑距离.md | 2 +-
problems/0077.组合.md | 2 +-
problems/0077.组合优化.md | 2 +-
problems/0078.子集.md | 2 +-
problems/0084.柱状图中最大的矩形.md | 2 +-
problems/0090.子集II.md | 2 +-
problems/0093.复原IP地址.md | 2 +-
problems/0096.不同的二叉搜索树.md | 2 +-
problems/0098.验证二叉搜索树.md | 2 +-
problems/0100.相同的树.md | 2 +-
problems/0101.对称二叉树.md | 2 +-
problems/0102.二叉树的层序遍历.md | 2 +-
problems/0104.二叉树的最大深度.md | 2 +-
problems/0106.从中序与后序遍历序列构造二叉树.md | 2 +-
problems/0108.将有序数组转换为二叉搜索树.md | 2 +-
problems/0110.平衡二叉树.md | 2 +-
problems/0111.二叉树的最小深度.md | 2 +-
problems/0112.路径总和.md | 2 +-
problems/0115.不同的子序列.md | 2 +-
problems/0116.填充每个节点的下一个右侧节点指针.md | 2 +-
problems/0121.买卖股票的最佳时机.md | 2 +-
problems/0122.买卖股票的最佳时机II.md | 2 +-
problems/0122.买卖股票的最佳时机II(动态规划).md | 2 +-
problems/0123.买卖股票的最佳时机III.md | 2 +-
problems/0127.单词接龙.md | 2 +-
problems/0129.求根到叶子节点数字之和.md | 2 +-
problems/0131.分割回文串.md | 2 +-
problems/0132.分割回文串II.md | 2 +-
problems/0134.加油站.md | 2 +-
problems/0135.分发糖果.md | 2 +-
problems/0139.单词拆分.md | 2 +-
problems/0141.环形链表.md | 2 +-
problems/0142.环形链表II.md | 2 +-
problems/0143.重排链表.md | 2 +-
problems/0150.逆波兰表达式求值.md | 2 +-
problems/0151.翻转字符串里的单词.md | 2 +-
problems/0160.相交链表.md | 2 +-
problems/0188.买卖股票的最佳时机IV.md | 2 +-
problems/0189.旋转数组.md | 2 +-
problems/0198.打家劫舍.md | 2 +-
problems/0202.快乐数.md | 2 +-
problems/0203.移除链表元素.md | 2 +-
problems/0205.同构字符串.md | 2 +-
problems/0206.翻转链表.md | 2 +-
problems/0209.长度最小的子数组.md | 2 +-
problems/0213.打家劫舍II.md | 2 +-
problems/0216.组合总和III.md | 2 +-
problems/0222.完全二叉树的节点个数.md | 2 +-
problems/0225.用队列实现栈.md | 2 +-
problems/0226.翻转二叉树.md | 2 +-
problems/0232.用栈实现队列.md | 2 +-
problems/0234.回文链表.md | 2 +-
problems/0235.二叉搜索树的最近公共祖先.md | 2 +-
problems/0236.二叉树的最近公共祖先.md | 2 +-
problems/0239.滑动窗口最大值.md | 2 +-
problems/0242.有效的字母异位词.md | 2 +-
problems/0257.二叉树的所有路径.md | 2 +-
problems/0279.完全平方数.md | 2 +-
problems/0283.移动零.md | 2 +-
problems/0300.最长上升子序列.md | 2 +-
problems/0309.最佳买卖股票时机含冷冻期.md | 2 +-
problems/0322.零钱兑换.md | 2 +-
problems/0332.重新安排行程.md | 2 +-
problems/0337.打家劫舍III.md | 2 +-
problems/0343.整数拆分.md | 2 +-
problems/0344.反转字符串.md | 2 +-
problems/0347.前K个高频元素.md | 2 +-
problems/0349.两个数组的交集.md | 2 +-
problems/0376.摆动序列.md | 2 +-
problems/0377.组合总和Ⅳ.md | 2 +-
problems/0383.赎金信.md | 2 +-
problems/0392.判断子序列.md | 2 +-
problems/0404.左叶子之和.md | 2 +-
problems/0406.根据身高重建队列.md | 2 +-
problems/0416.分割等和子集.md | 2 +-
problems/0435.无重叠区间.md | 2 +-
problems/0450.删除二叉搜索树中的节点.md | 2 +-
problems/0452.用最少数量的箭引爆气球.md | 2 +-
problems/0454.四数相加II.md | 2 +-
problems/0455.分发饼干.md | 2 +-
problems/0459.重复的子字符串.md | 2 +-
problems/0463.岛屿的周长.md | 2 +-
problems/0474.一和零.md | 2 +-
problems/0491.递增子序列.md | 2 +-
problems/0494.目标和.md | 2 +-
problems/0496.下一个更大元素I.md | 2 +-
problems/0501.二叉搜索树中的众数.md | 2 +-
problems/0503.下一个更大元素II.md | 2 +-
problems/0509.斐波那契数.md | 2 +-
problems/0513.找树左下角的值.md | 2 +-
problems/0516.最长回文子序列.md | 2 +-
problems/0518.零钱兑换II.md | 2 +-
problems/0530.二叉搜索树的最小绝对差.md | 2 +-
problems/0538.把二叉搜索树转换为累加树.md | 2 +-
problems/0541.反转字符串II.md | 2 +-
problems/0583.两个字符串的删除操作.md | 2 +-
problems/0617.合并二叉树.md | 2 +-
problems/0647.回文子串.md | 2 +-
problems/0649.Dota2参议院.md | 2 +-
problems/0654.最大二叉树.md | 2 +-
problems/0657.机器人能否返回原点.md | 2 +-
problems/0669.修剪二叉搜索树.md | 2 +-
problems/0673.最长递增子序列的个数.md | 2 +-
problems/0674.最长连续递增序列.md | 2 +-
problems/0684.冗余连接.md | 2 +-
problems/0685.冗余连接II.md | 2 +-
problems/0700.二叉搜索树中的搜索.md | 2 +-
problems/0701.二叉搜索树中的插入操作.md | 2 +-
problems/0704.二分查找.md | 2 +-
problems/0707.设计链表.md | 2 +-
problems/0714.买卖股票的最佳时机含手续费.md | 2 +-
problems/0714.买卖股票的最佳时机含手续费(动态规划).md | 2 +-
problems/0718.最长重复子数组.md | 2 +-
problems/0724.寻找数组的中心索引.md | 2 +-
problems/0738.单调递增的数字.md | 2 +-
problems/0739.每日温度.md | 2 +-
problems/0746.使用最小花费爬楼梯.md | 2 +-
problems/0763.划分字母区间.md | 2 +-
problems/0841.钥匙和房间.md | 2 +-
problems/0844.比较含退格的字符串.md | 2 +-
problems/0860.柠檬水找零.md | 2 +-
problems/0922.按奇偶排序数组II.md | 2 +-
problems/0925.长按键入.md | 2 +-
problems/0941.有效的山脉数组.md | 2 +-
problems/0968.监控二叉树.md | 2 +-
problems/0977.有序数组的平方.md | 2 +-
problems/1002.查找常用字符.md | 2 +-
problems/1005.K次取反后最大化的数组和.md | 2 +-
problems/1035.不相交的线.md | 2 +-
problems/1047.删除字符串中的所有相邻重复项.md | 2 +-
problems/1049.最后一块石头的重量II.md | 2 +-
problems/1143.最长公共子序列.md | 2 +-
problems/1207.独一无二的出现次数.md | 2 +-
problems/1221.分割平衡字符串.md | 2 +-
problems/1356.根据数字二进制下1的数目排序.md | 2 +-
problems/1365.有多少小于当前数字的数字.md | 2 +-
problems/1382.将二叉搜索树变平衡.md | 2 +-
problems/O(n)的算法居然超时了,此时的n究竟是多大?.md | 2 +-
problems/为了绝杀编辑距离,卡尔做了三步铺垫.md | 2 +-
problems/二叉树中递归带着回溯.md | 2 +-
problems/二叉树总结篇.md | 2 +-
problems/二叉树理论基础.md | 2 +-
problems/二叉树的统一迭代法.md | 2 +-
problems/二叉树的迭代遍历.md | 2 +-
problems/二叉树的递归遍历.md | 2 +-
problems/关于时间复杂度,你不知道的都在这里!.md | 2 +-
problems/剑指Offer05.替换空格.md | 2 +-
problems/剑指Offer58-II.左旋转字符串.md | 2 +-
problems/动态规划-股票问题总结篇.md | 2 +-
problems/动态规划总结篇.md | 2 +-
problems/动态规划理论基础.md | 2 +-
problems/双指针总结.md | 2 +-
problems/哈希表总结.md | 2 +-
problems/哈希表理论基础.md | 2 +-
problems/回溯总结.md | 2 +-
problems/回溯算法去重问题的另一种写法.md | 2 +-
problems/回溯算法理论基础.md | 2 +-
problems/字符串总结.md | 2 +-
problems/数组总结篇.md | 2 +-
problems/数组理论基础.md | 2 +-
problems/栈与队列总结.md | 2 +-
problems/栈与队列理论基础.md | 2 +-
problems/根据身高重建队列(vector原理讲解).md | 2 +-
problems/算法模板.md | 2 +-
problems/背包总结篇.md | 2 +-
problems/背包理论基础01背包-1.md | 2 +-
problems/背包理论基础01背包-2.md | 2 +-
problems/背包问题理论基础多重背包.md | 2 +-
problems/背包问题理论基础完全背包.md | 2 +-
problems/贪心算法总结篇.md | 2 +-
problems/贪心算法理论基础.md | 2 +-
problems/链表总结篇.md | 2 +-
problems/链表理论基础.md | 2 +-
problems/面试题02.07.链表相交.md | 2 +-
204 files changed, 204 insertions(+), 204 deletions(-)
diff --git a/problems/0005.最长回文子串.md b/problems/0005.最长回文子串.md
index 98df800a..82d9edae 100644
--- a/problems/0005.最长回文子串.md
+++ b/problems/0005.最长回文子串.md
@@ -443,4 +443,4 @@ var longestPalindrome = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0015.三数之和.md b/problems/0015.三数之和.md
index d00b76bd..5c9a240b 100644
--- a/problems/0015.三数之和.md
+++ b/problems/0015.三数之和.md
@@ -441,4 +441,4 @@ func threeSum(_ nums: [Int]) -> [[Int]] {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0017.电话号码的字母组合.md b/problems/0017.电话号码的字母组合.md
index 3dff97e5..15a486f2 100644
--- a/problems/0017.电话号码的字母组合.md
+++ b/problems/0017.电话号码的字母组合.md
@@ -475,4 +475,4 @@ char ** letterCombinations(char * digits, int* returnSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0018.四数之和.md b/problems/0018.四数之和.md
index ddeb3c96..e1d0d03c 100644
--- a/problems/0018.四数之和.md
+++ b/problems/0018.四数之和.md
@@ -407,4 +407,4 @@ func fourSum(_ nums: [Int], _ target: Int) -> [[Int]] {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0019.删除链表的倒数第N个节点.md b/problems/0019.删除链表的倒数第N个节点.md
index f54b1629..0e8aeaec 100644
--- a/problems/0019.删除链表的倒数第N个节点.md
+++ b/problems/0019.删除链表的倒数第N个节点.md
@@ -233,4 +233,4 @@ func removeNthFromEnd(_ head: ListNode?, _ n: Int) -> ListNode? {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0020.有效的括号.md b/problems/0020.有效的括号.md
index 918a3560..bf0884b3 100644
--- a/problems/0020.有效的括号.md
+++ b/problems/0020.有效的括号.md
@@ -290,4 +290,4 @@ var isValid = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0024.两两交换链表中的节点.md b/problems/0024.两两交换链表中的节点.md
index 19c2a06e..11828ca0 100644
--- a/problems/0024.两两交换链表中的节点.md
+++ b/problems/0024.两两交换链表中的节点.md
@@ -283,4 +283,4 @@ func swapPairs(_ head: ListNode?) -> ListNode? {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0027.移除元素.md b/problems/0027.移除元素.md
index 21216945..842b3c78 100644
--- a/problems/0027.移除元素.md
+++ b/problems/0027.移除元素.md
@@ -290,4 +290,4 @@ int removeElement(int* nums, int numsSize, int val){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0028.实现strStr.md b/problems/0028.实现strStr.md
index 35bec96d..2a7b9cfa 100644
--- a/problems/0028.实现strStr.md
+++ b/problems/0028.实现strStr.md
@@ -902,4 +902,4 @@ var strStr = function (haystack, needle) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0031.下一个排列.md b/problems/0031.下一个排列.md
index 6da71139..9efcb06a 100644
--- a/problems/0031.下一个排列.md
+++ b/problems/0031.下一个排列.md
@@ -185,4 +185,4 @@ var nextPermutation = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
index 22963b6f..d70dcba5 100644
--- a/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
+++ b/problems/0034.在排序数组中查找元素的第一个和最后一个位置.md
@@ -443,4 +443,4 @@ var searchRange = function(nums, target) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md
index b25bfe54..593e3fe5 100644
--- a/problems/0035.搜索插入位置.md
+++ b/problems/0035.搜索插入位置.md
@@ -313,4 +313,4 @@ func searchInsert(_ nums: [Int], _ target: Int) -> Int {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0037.解数独.md b/problems/0037.解数独.md
index 468cd3a6..7bc07252 100644
--- a/problems/0037.解数独.md
+++ b/problems/0037.解数独.md
@@ -556,4 +556,4 @@ void solveSudoku(char** board, int boardSize, int* boardColSize) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0039.组合总和.md b/problems/0039.组合总和.md
index 369d1cb9..e6f65700 100644
--- a/problems/0039.组合总和.md
+++ b/problems/0039.组合总和.md
@@ -405,4 +405,4 @@ int** combinationSum(int* candidates, int candidatesSize, int target, int* retur
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0040.组合总和II.md b/problems/0040.组合总和II.md
index 6d0460eb..13e0b35f 100644
--- a/problems/0040.组合总和II.md
+++ b/problems/0040.组合总和II.md
@@ -458,4 +458,4 @@ int** combinationSum2(int* candidates, int candidatesSize, int target, int* retu
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index ae61fac9..f0d0ecb3 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -676,4 +676,4 @@ int trap(int* height, int heightSize) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0045.跳跃游戏II.md b/problems/0045.跳跃游戏II.md
index 31b6ee2e..43c2f019 100644
--- a/problems/0045.跳跃游戏II.md
+++ b/problems/0045.跳跃游戏II.md
@@ -236,4 +236,4 @@ var jump = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md
index bba7dd6a..487a07ad 100644
--- a/problems/0046.全排列.md
+++ b/problems/0046.全排列.md
@@ -315,4 +315,4 @@ var permute = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0047.全排列II.md b/problems/0047.全排列II.md
index 085b686e..4c2c2758 100644
--- a/problems/0047.全排列II.md
+++ b/problems/0047.全排列II.md
@@ -338,4 +338,4 @@ func backTring(nums,subRes []int,res *[][]int,used []bool){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0051.N皇后.md b/problems/0051.N皇后.md
index fa2d2ab7..7e2b202f 100644
--- a/problems/0051.N皇后.md
+++ b/problems/0051.N皇后.md
@@ -499,4 +499,4 @@ var solveNQueens = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0052.N皇后II.md b/problems/0052.N皇后II.md
index 51cb5812..6d7a5bac 100644
--- a/problems/0052.N皇后II.md
+++ b/problems/0052.N皇后II.md
@@ -149,4 +149,4 @@ var totalNQueens = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0053.最大子序和.md b/problems/0053.最大子序和.md
index da67bfd7..75281210 100644
--- a/problems/0053.最大子序和.md
+++ b/problems/0053.最大子序和.md
@@ -216,4 +216,4 @@ var maxSubArray = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0053.最大子序和(动态规划).md b/problems/0053.最大子序和(动态规划).md
index ebf4541c..2c3ccc15 100644
--- a/problems/0053.最大子序和(动态规划).md
+++ b/problems/0053.最大子序和(动态规划).md
@@ -192,4 +192,4 @@ const maxSubArray = nums => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md
index 0c936131..816eb64b 100644
--- a/problems/0055.跳跃游戏.md
+++ b/problems/0055.跳跃游戏.md
@@ -161,4 +161,4 @@ var canJump = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0056.合并区间.md b/problems/0056.合并区间.md
index 6332d5a9..93c0a2a0 100644
--- a/problems/0056.合并区间.md
+++ b/problems/0056.合并区间.md
@@ -248,4 +248,4 @@ var merge = function (intervals) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0059.螺旋矩阵II.md b/problems/0059.螺旋矩阵II.md
index 99750f60..994bd839 100644
--- a/problems/0059.螺旋矩阵II.md
+++ b/problems/0059.螺旋矩阵II.md
@@ -542,4 +542,4 @@ int** generateMatrix(int n, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0062.不同路径.md b/problems/0062.不同路径.md
index 4d0381e0..af3a8f40 100644
--- a/problems/0062.不同路径.md
+++ b/problems/0062.不同路径.md
@@ -333,4 +333,4 @@ var uniquePaths = function(m, n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0063.不同路径II.md b/problems/0063.不同路径II.md
index 322de75e..c2f8ec20 100644
--- a/problems/0063.不同路径II.md
+++ b/problems/0063.不同路径II.md
@@ -341,4 +341,4 @@ var uniquePathsWithObstacles = function(obstacleGrid) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0070.爬楼梯.md b/problems/0070.爬楼梯.md
index 54d026ab..97926e7a 100644
--- a/problems/0070.爬楼梯.md
+++ b/problems/0070.爬楼梯.md
@@ -301,4 +301,4 @@ var climbStairs = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md
index 6ef694f8..104b2d5a 100644
--- a/problems/0070.爬楼梯完全背包版本.md
+++ b/problems/0070.爬楼梯完全背包版本.md
@@ -206,4 +206,4 @@ var climbStairs = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0072.编辑距离.md b/problems/0072.编辑距离.md
index ca8e85b8..8096c0ad 100644
--- a/problems/0072.编辑距离.md
+++ b/problems/0072.编辑距离.md
@@ -333,4 +333,4 @@ const minDistance = (word1, word2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0077.组合.md b/problems/0077.组合.md
index 6f6f89a6..ee2a4cb6 100644
--- a/problems/0077.组合.md
+++ b/problems/0077.组合.md
@@ -627,4 +627,4 @@ int** combine(int n, int k, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0077.组合优化.md b/problems/0077.组合优化.md
index 02b30d3d..3282d790 100644
--- a/problems/0077.组合优化.md
+++ b/problems/0077.组合优化.md
@@ -300,4 +300,4 @@ int** combine(int n, int k, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0078.子集.md b/problems/0078.子集.md
index 59f291d0..878133a1 100644
--- a/problems/0078.子集.md
+++ b/problems/0078.子集.md
@@ -325,4 +325,4 @@ int** subsets(int* nums, int numsSize, int* returnSize, int** returnColumnSizes)
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0084.柱状图中最大的矩形.md b/problems/0084.柱状图中最大的矩形.md
index 9c7035f2..ccb59fbe 100644
--- a/problems/0084.柱状图中最大的矩形.md
+++ b/problems/0084.柱状图中最大的矩形.md
@@ -407,4 +407,4 @@ var largestRectangleArea = function(heights) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0090.子集II.md b/problems/0090.子集II.md
index d2a9279f..7ae7c6c2 100644
--- a/problems/0090.子集II.md
+++ b/problems/0090.子集II.md
@@ -353,4 +353,4 @@ int** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColum
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md
index 26103318..4e56ddc4 100644
--- a/problems/0093.复原IP地址.md
+++ b/problems/0093.复原IP地址.md
@@ -524,4 +524,4 @@ char ** restoreIpAddresses(char * s, int* returnSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0096.不同的二叉搜索树.md b/problems/0096.不同的二叉搜索树.md
index 76d7d353..38a4ad88 100644
--- a/problems/0096.不同的二叉搜索树.md
+++ b/problems/0096.不同的二叉搜索树.md
@@ -234,4 +234,4 @@ const numTrees =(n) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0098.验证二叉搜索树.md b/problems/0098.验证二叉搜索树.md
index c7e5b4e6..fcd92862 100644
--- a/problems/0098.验证二叉搜索树.md
+++ b/problems/0098.验证二叉搜索树.md
@@ -529,4 +529,4 @@ var isValidBST = function (root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0100.相同的树.md b/problems/0100.相同的树.md
index c7431c5e..f5672b72 100644
--- a/problems/0100.相同的树.md
+++ b/problems/0100.相同的树.md
@@ -247,4 +247,4 @@ JavaScript:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0101.对称二叉树.md b/problems/0101.对称二叉树.md
index 196e0b58..fe3321ec 100644
--- a/problems/0101.对称二叉树.md
+++ b/problems/0101.对称二叉树.md
@@ -582,4 +582,4 @@ var isSymmetric = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0102.二叉树的层序遍历.md b/problems/0102.二叉树的层序遍历.md
index da4398f5..37f4f526 100644
--- a/problems/0102.二叉树的层序遍历.md
+++ b/problems/0102.二叉树的层序遍历.md
@@ -1906,4 +1906,4 @@ var minDepth = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md
index 4162de80..e20f147f 100644
--- a/problems/0104.二叉树的最大深度.md
+++ b/problems/0104.二叉树的最大深度.md
@@ -586,4 +586,4 @@ var maxDepth = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md
index 68f4419a..a83341fd 100644
--- a/problems/0106.从中序与后序遍历序列构造二叉树.md
+++ b/problems/0106.从中序与后序遍历序列构造二叉树.md
@@ -823,4 +823,4 @@ var buildTree = function(preorder, inorder) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0108.将有序数组转换为二叉搜索树.md b/problems/0108.将有序数组转换为二叉搜索树.md
index 9b260db1..f2bfbb3b 100644
--- a/problems/0108.将有序数组转换为二叉搜索树.md
+++ b/problems/0108.将有序数组转换为二叉搜索树.md
@@ -362,4 +362,4 @@ var sortedArrayToBST = function (nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0110.平衡二叉树.md b/problems/0110.平衡二叉树.md
index bd2fe432..7858fa60 100644
--- a/problems/0110.平衡二叉树.md
+++ b/problems/0110.平衡二叉树.md
@@ -624,4 +624,4 @@ var isBalanced = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0111.二叉树的最小深度.md b/problems/0111.二叉树的最小深度.md
index 3cfed997..7fc69065 100644
--- a/problems/0111.二叉树的最小深度.md
+++ b/problems/0111.二叉树的最小深度.md
@@ -413,4 +413,4 @@ var minDepth = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md
index 9bb470e6..bfb03424 100644
--- a/problems/0112.路径总和.md
+++ b/problems/0112.路径总和.md
@@ -711,4 +711,4 @@ var pathsum = function(root, targetsum) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0115.不同的子序列.md b/problems/0115.不同的子序列.md
index 3de9b3e1..5fe69b96 100644
--- a/problems/0115.不同的子序列.md
+++ b/problems/0115.不同的子序列.md
@@ -274,4 +274,4 @@ const numDistinct = (s, t) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0116.填充每个节点的下一个右侧节点指针.md b/problems/0116.填充每个节点的下一个右侧节点指针.md
index be6c31e8..5aca82e1 100644
--- a/problems/0116.填充每个节点的下一个右侧节点指针.md
+++ b/problems/0116.填充每个节点的下一个右侧节点指针.md
@@ -260,4 +260,4 @@ const connect = root => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0121.买卖股票的最佳时机.md b/problems/0121.买卖股票的最佳时机.md
index 9592c442..e30fa50a 100644
--- a/problems/0121.买卖股票的最佳时机.md
+++ b/problems/0121.买卖股票的最佳时机.md
@@ -360,4 +360,4 @@ const maxProfit = prices => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0122.买卖股票的最佳时机II.md b/problems/0122.买卖股票的最佳时机II.md
index 061ffe19..41d83847 100644
--- a/problems/0122.买卖股票的最佳时机II.md
+++ b/problems/0122.买卖股票的最佳时机II.md
@@ -286,4 +286,4 @@ int maxProfit(int* prices, int pricesSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0122.买卖股票的最佳时机II(动态规划).md b/problems/0122.买卖股票的最佳时机II(动态规划).md
index 31a8e6dc..4e64beaf 100644
--- a/problems/0122.买卖股票的最佳时机II(动态规划).md
+++ b/problems/0122.买卖股票的最佳时机II(动态规划).md
@@ -246,4 +246,4 @@ const maxProfit = (prices) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0123.买卖股票的最佳时机III.md b/problems/0123.买卖股票的最佳时机III.md
index 80aa740f..fec39853 100644
--- a/problems/0123.买卖股票的最佳时机III.md
+++ b/problems/0123.买卖股票的最佳时机III.md
@@ -324,4 +324,4 @@ const maxProfit = prices => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0127.单词接龙.md b/problems/0127.单词接龙.md
index 5a4edb9c..ad8467b5 100644
--- a/problems/0127.单词接龙.md
+++ b/problems/0127.单词接龙.md
@@ -181,4 +181,4 @@ var ladderLength = function(beginWord, endWord, wordList) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0129.求根到叶子节点数字之和.md b/problems/0129.求根到叶子节点数字之和.md
index 86ed4eb2..54b7e44d 100644
--- a/problems/0129.求根到叶子节点数字之和.md
+++ b/problems/0129.求根到叶子节点数字之和.md
@@ -297,4 +297,4 @@ var sumNumbers = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md
index 81aa1522..811044da 100644
--- a/problems/0131.分割回文串.md
+++ b/problems/0131.分割回文串.md
@@ -424,4 +424,4 @@ var partition = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0132.分割回文串II.md b/problems/0132.分割回文串II.md
index b104115a..dfb0ea93 100644
--- a/problems/0132.分割回文串II.md
+++ b/problems/0132.分割回文串II.md
@@ -290,4 +290,4 @@ var minCut = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0134.加油站.md b/problems/0134.加油站.md
index 65bff8e9..7674c000 100644
--- a/problems/0134.加油站.md
+++ b/problems/0134.加油站.md
@@ -379,4 +379,4 @@ int canCompleteCircuit(int* gas, int gasSize, int* cost, int costSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0135.分发糖果.md b/problems/0135.分发糖果.md
index dddb4488..ace6bc7d 100644
--- a/problems/0135.分发糖果.md
+++ b/problems/0135.分发糖果.md
@@ -242,4 +242,4 @@ var candy = function(ratings) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0139.单词拆分.md b/problems/0139.单词拆分.md
index b3158cb3..4af116a4 100644
--- a/problems/0139.单词拆分.md
+++ b/problems/0139.单词拆分.md
@@ -319,4 +319,4 @@ const wordBreak = (s, wordDict) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0141.环形链表.md b/problems/0141.环形链表.md
index 70e2deb1..559ded41 100644
--- a/problems/0141.环形链表.md
+++ b/problems/0141.环形链表.md
@@ -132,4 +132,4 @@ var hasCycle = function(head) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0142.环形链表II.md b/problems/0142.环形链表II.md
index 52ff7686..2e20e17e 100644
--- a/problems/0142.环形链表II.md
+++ b/problems/0142.环形链表II.md
@@ -334,4 +334,4 @@ extension ListNode: Equatable {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0143.重排链表.md b/problems/0143.重排链表.md
index cc82e625..c5ac9bae 100644
--- a/problems/0143.重排链表.md
+++ b/problems/0143.重排链表.md
@@ -461,4 +461,4 @@ var reorderList = function(head, s = [], tmp) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0150.逆波兰表达式求值.md b/problems/0150.逆波兰表达式求值.md
index 859a6d98..0711803c 100644
--- a/problems/0150.逆波兰表达式求值.md
+++ b/problems/0150.逆波兰表达式求值.md
@@ -248,4 +248,4 @@ class Solution:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0151.翻转字符串里的单词.md b/problems/0151.翻转字符串里的单词.md
index 7902a398..8d28b332 100644
--- a/problems/0151.翻转字符串里的单词.md
+++ b/problems/0151.翻转字符串里的单词.md
@@ -553,4 +553,4 @@ func reverseWord(_ s: inout [Character]) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0160.相交链表.md b/problems/0160.相交链表.md
index ce7296b3..1c513180 100644
--- a/problems/0160.相交链表.md
+++ b/problems/0160.相交链表.md
@@ -11,4 +11,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0188.买卖股票的最佳时机IV.md b/problems/0188.买卖股票的最佳时机IV.md
index a0520fb4..5cffbe9e 100644
--- a/problems/0188.买卖股票的最佳时机IV.md
+++ b/problems/0188.买卖股票的最佳时机IV.md
@@ -331,4 +331,4 @@ var maxProfit = function(k, prices) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0189.旋转数组.md b/problems/0189.旋转数组.md
index a08ee83e..c876a27a 100644
--- a/problems/0189.旋转数组.md
+++ b/problems/0189.旋转数组.md
@@ -155,4 +155,4 @@ var rotate = function (nums, k) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0198.打家劫舍.md b/problems/0198.打家劫舍.md
index 4bf8a81a..66e95f28 100644
--- a/problems/0198.打家劫舍.md
+++ b/problems/0198.打家劫舍.md
@@ -198,4 +198,4 @@ const rob = nums => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0202.快乐数.md b/problems/0202.快乐数.md
index 8f2e3bae..5704283d 100644
--- a/problems/0202.快乐数.md
+++ b/problems/0202.快乐数.md
@@ -284,4 +284,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0203.移除链表元素.md b/problems/0203.移除链表元素.md
index 61c3e8ef..a41252de 100644
--- a/problems/0203.移除链表元素.md
+++ b/problems/0203.移除链表元素.md
@@ -362,4 +362,4 @@ func removeElements(head *ListNode, val int) *ListNode {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0205.同构字符串.md b/problems/0205.同构字符串.md
index f68d4916..1eebd19d 100644
--- a/problems/0205.同构字符串.md
+++ b/problems/0205.同构字符串.md
@@ -145,4 +145,4 @@ var isIsomorphic = function(s, t) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 3814b53d..96cd7c1e 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -375,4 +375,4 @@ func reverse(pre: ListNode?, cur: ListNode?) -> ListNode? {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0209.长度最小的子数组.md b/problems/0209.长度最小的子数组.md
index fe3657c0..cc6b3bba 100644
--- a/problems/0209.长度最小的子数组.md
+++ b/problems/0209.长度最小的子数组.md
@@ -297,4 +297,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0213.打家劫舍II.md b/problems/0213.打家劫舍II.md
index 044769d5..6f753a72 100644
--- a/problems/0213.打家劫舍II.md
+++ b/problems/0213.打家劫舍II.md
@@ -174,4 +174,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0216.组合总和III.md b/problems/0216.组合总和III.md
index a6660d7a..8c9dcac2 100644
--- a/problems/0216.组合总和III.md
+++ b/problems/0216.组合总和III.md
@@ -454,4 +454,4 @@ int** combinationSum3(int k, int n, int* returnSize, int** returnColumnSizes){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0222.完全二叉树的节点个数.md b/problems/0222.完全二叉树的节点个数.md
index 13f9f54d..dc09985d 100644
--- a/problems/0222.完全二叉树的节点个数.md
+++ b/problems/0222.完全二叉树的节点个数.md
@@ -455,4 +455,4 @@ var countNodes = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0225.用队列实现栈.md b/problems/0225.用队列实现栈.md
index 3723f4a7..5adba07f 100644
--- a/problems/0225.用队列实现栈.md
+++ b/problems/0225.用队列实现栈.md
@@ -538,4 +538,4 @@ MyStack.prototype.empty = function() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0226.翻转二叉树.md b/problems/0226.翻转二叉树.md
index 157ee05c..c4ad42ca 100644
--- a/problems/0226.翻转二叉树.md
+++ b/problems/0226.翻转二叉树.md
@@ -569,4 +569,4 @@ var invertTree = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0232.用栈实现队列.md b/problems/0232.用栈实现队列.md
index ba12e0ab..40406f51 100644
--- a/problems/0232.用栈实现队列.md
+++ b/problems/0232.用栈实现队列.md
@@ -356,4 +356,4 @@ MyQueue.prototype.empty = function() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0234.回文链表.md b/problems/0234.回文链表.md
index b3d55ada..db02a6ba 100644
--- a/problems/0234.回文链表.md
+++ b/problems/0234.回文链表.md
@@ -327,4 +327,4 @@ var isPalindrome = function(head) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0235.二叉搜索树的最近公共祖先.md b/problems/0235.二叉搜索树的最近公共祖先.md
index 1d36ce37..fb1bd42c 100644
--- a/problems/0235.二叉搜索树的最近公共祖先.md
+++ b/problems/0235.二叉搜索树的最近公共祖先.md
@@ -357,4 +357,4 @@ var lowestCommonAncestor = function(root, p, q) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0236.二叉树的最近公共祖先.md b/problems/0236.二叉树的最近公共祖先.md
index 215cb021..a469869a 100644
--- a/problems/0236.二叉树的最近公共祖先.md
+++ b/problems/0236.二叉树的最近公共祖先.md
@@ -345,4 +345,4 @@ var lowestCommonAncestor = function(root, p, q) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0239.滑动窗口最大值.md b/problems/0239.滑动窗口最大值.md
index 48c65837..be46bd05 100644
--- a/problems/0239.滑动窗口最大值.md
+++ b/problems/0239.滑动窗口最大值.md
@@ -425,4 +425,4 @@ var maxSlidingWindow = function (nums, k) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0242.有效的字母异位词.md b/problems/0242.有效的字母异位词.md
index c6981587..b0475a26 100644
--- a/problems/0242.有效的字母异位词.md
+++ b/problems/0242.有效的字母异位词.md
@@ -286,4 +286,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md
index 7438f924..c85186d5 100644
--- a/problems/0257.二叉树的所有路径.md
+++ b/problems/0257.二叉树的所有路径.md
@@ -516,4 +516,4 @@ var binaryTreePaths = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0279.完全平方数.md b/problems/0279.完全平方数.md
index ca7c4966..a00ed47e 100644
--- a/problems/0279.完全平方数.md
+++ b/problems/0279.完全平方数.md
@@ -361,4 +361,4 @@ var numSquares2 = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0283.移动零.md b/problems/0283.移动零.md
index 5ff2871c..2e8743e3 100644
--- a/problems/0283.移动零.md
+++ b/problems/0283.移动零.md
@@ -116,4 +116,4 @@ var moveZeroes = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0300.最长上升子序列.md b/problems/0300.最长上升子序列.md
index fe88ef26..fe95cfed 100644
--- a/problems/0300.最长上升子序列.md
+++ b/problems/0300.最长上升子序列.md
@@ -202,4 +202,4 @@ const lengthOfLIS = (nums) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0309.最佳买卖股票时机含冷冻期.md b/problems/0309.最佳买卖股票时机含冷冻期.md
index 47da9584..2d0ee105 100644
--- a/problems/0309.最佳买卖股票时机含冷冻期.md
+++ b/problems/0309.最佳买卖股票时机含冷冻期.md
@@ -237,4 +237,4 @@ const maxProfit = (prices) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0322.零钱兑换.md b/problems/0322.零钱兑换.md
index 8e03b391..63bde655 100644
--- a/problems/0322.零钱兑换.md
+++ b/problems/0322.零钱兑换.md
@@ -330,4 +330,4 @@ const coinChange = (coins, amount) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0332.重新安排行程.md b/problems/0332.重新安排行程.md
index 6f993e3e..9a9cada9 100644
--- a/problems/0332.重新安排行程.md
+++ b/problems/0332.重新安排行程.md
@@ -450,4 +450,4 @@ var findItinerary = function(tickets) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0337.打家劫舍III.md b/problems/0337.打家劫舍III.md
index f65bcdb6..949137c3 100644
--- a/problems/0337.打家劫舍III.md
+++ b/problems/0337.打家劫舍III.md
@@ -402,4 +402,4 @@ const rob = root => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0343.整数拆分.md b/problems/0343.整数拆分.md
index 1f025051..78c94f2a 100644
--- a/problems/0343.整数拆分.md
+++ b/problems/0343.整数拆分.md
@@ -276,4 +276,4 @@ var integerBreak = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md
index 8dc0e082..17543486 100644
--- a/problems/0344.反转字符串.md
+++ b/problems/0344.反转字符串.md
@@ -233,4 +233,4 @@ func reverseString(_ s: inout [Character]) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0347.前K个高频元素.md b/problems/0347.前K个高频元素.md
index 315c184b..941878d4 100644
--- a/problems/0347.前K个高频元素.md
+++ b/problems/0347.前K个高频元素.md
@@ -364,4 +364,4 @@ PriorityQueue.prototype.compare = function(index1, index2) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md
index 8c170ed9..3f39f889 100644
--- a/problems/0349.两个数组的交集.md
+++ b/problems/0349.两个数组的交集.md
@@ -266,4 +266,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md
index 74a75ef1..23348bd0 100644
--- a/problems/0376.摆动序列.md
+++ b/problems/0376.摆动序列.md
@@ -192,4 +192,4 @@ var wiggleMaxLength = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0377.组合总和Ⅳ.md b/problems/0377.组合总和Ⅳ.md
index 81e9dee3..2a507c42 100644
--- a/problems/0377.组合总和Ⅳ.md
+++ b/problems/0377.组合总和Ⅳ.md
@@ -246,4 +246,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md
index ac851fcd..d227dde0 100644
--- a/problems/0383.赎金信.md
+++ b/problems/0383.赎金信.md
@@ -342,4 +342,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0392.判断子序列.md b/problems/0392.判断子序列.md
index 43cfbe7e..cda0c82d 100644
--- a/problems/0392.判断子序列.md
+++ b/problems/0392.判断子序列.md
@@ -231,4 +231,4 @@ func isSubsequence(s string, t string) bool {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md
index 1fac7c9b..e55981e2 100644
--- a/problems/0404.左叶子之和.md
+++ b/problems/0404.左叶子之和.md
@@ -382,4 +382,4 @@ var sumOfLeftLeaves = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md
index 91e10cd5..f7d9d805 100644
--- a/problems/0406.根据身高重建队列.md
+++ b/problems/0406.根据身高重建队列.md
@@ -297,4 +297,4 @@ var reconstructQueue = function(people) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0416.分割等和子集.md b/problems/0416.分割等和子集.md
index 60695d1e..fd20f68a 100644
--- a/problems/0416.分割等和子集.md
+++ b/problems/0416.分割等和子集.md
@@ -293,4 +293,4 @@ var canPartition = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md
index 282404d8..79083716 100644
--- a/problems/0435.无重叠区间.md
+++ b/problems/0435.无重叠区间.md
@@ -319,4 +319,4 @@ var eraseOverlapIntervals = function(intervals) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0450.删除二叉搜索树中的节点.md b/problems/0450.删除二叉搜索树中的节点.md
index 6fa7fa2d..32dd862e 100644
--- a/problems/0450.删除二叉搜索树中的节点.md
+++ b/problems/0450.删除二叉搜索树中的节点.md
@@ -491,4 +491,4 @@ var deleteNode = function (root, key) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0452.用最少数量的箭引爆气球.md b/problems/0452.用最少数量的箭引爆气球.md
index 75ad01e8..c3c9b827 100644
--- a/problems/0452.用最少数量的箭引爆气球.md
+++ b/problems/0452.用最少数量的箭引爆气球.md
@@ -247,4 +247,4 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md
index 4f030268..d12f0233 100644
--- a/problems/0454.四数相加II.md
+++ b/problems/0454.四数相加II.md
@@ -286,4 +286,4 @@ impl Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0455.分发饼干.md b/problems/0455.分发饼干.md
index 41f04600..80a6172d 100644
--- a/problems/0455.分发饼干.md
+++ b/problems/0455.分发饼干.md
@@ -245,4 +245,4 @@ int findContentChildren(int* g, int gSize, int* s, int sSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0459.重复的子字符串.md b/problems/0459.重复的子字符串.md
index 6d9b8d9f..b193acdc 100644
--- a/problems/0459.重复的子字符串.md
+++ b/problems/0459.重复的子字符串.md
@@ -369,4 +369,4 @@ var repeatedSubstringPattern = function (s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0463.岛屿的周长.md b/problems/0463.岛屿的周长.md
index 9543afb8..3b0278a6 100644
--- a/problems/0463.岛屿的周长.md
+++ b/problems/0463.岛屿的周长.md
@@ -182,4 +182,4 @@ var islandPerimeter = function(grid) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0474.一和零.md b/problems/0474.一和零.md
index 108a5ee3..c8715b39 100644
--- a/problems/0474.一和零.md
+++ b/problems/0474.一和零.md
@@ -331,4 +331,4 @@ const findMaxForm = (strs, m, n) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md
index d793e23c..e947b2b9 100644
--- a/problems/0491.递增子序列.md
+++ b/problems/0491.递增子序列.md
@@ -385,4 +385,4 @@ int** findSubsequences(int* nums, int numsSize, int* returnSize, int** returnCol
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0494.目标和.md b/problems/0494.目标和.md
index a2388edf..210ac749 100644
--- a/problems/0494.目标和.md
+++ b/problems/0494.目标和.md
@@ -392,4 +392,4 @@ const findTargetSumWays = (nums, target) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0496.下一个更大元素I.md b/problems/0496.下一个更大元素I.md
index d7fd1d94..89549924 100644
--- a/problems/0496.下一个更大元素I.md
+++ b/problems/0496.下一个更大元素I.md
@@ -305,4 +305,4 @@ var nextGreaterElement = function (nums1, nums2) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0501.二叉搜索树中的众数.md b/problems/0501.二叉搜索树中的众数.md
index 1d24367e..29e5e139 100644
--- a/problems/0501.二叉搜索树中的众数.md
+++ b/problems/0501.二叉搜索树中的众数.md
@@ -690,4 +690,4 @@ var findMode = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0503.下一个更大元素II.md b/problems/0503.下一个更大元素II.md
index 13adc024..10b6edea 100644
--- a/problems/0503.下一个更大元素II.md
+++ b/problems/0503.下一个更大元素II.md
@@ -189,4 +189,4 @@ var nextGreaterElements = function (nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0509.斐波那契数.md b/problems/0509.斐波那契数.md
index 86591157..4102dd64 100644
--- a/problems/0509.斐波那契数.md
+++ b/problems/0509.斐波那契数.md
@@ -238,4 +238,4 @@ var fib = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0513.找树左下角的值.md b/problems/0513.找树左下角的值.md
index ef44f700..d09ec94d 100644
--- a/problems/0513.找树左下角的值.md
+++ b/problems/0513.找树左下角的值.md
@@ -441,4 +441,4 @@ var findBottomLeftValue = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0516.最长回文子序列.md b/problems/0516.最长回文子序列.md
index 629e9247..e413ea70 100644
--- a/problems/0516.最长回文子序列.md
+++ b/problems/0516.最长回文子序列.md
@@ -243,4 +243,4 @@ const longestPalindromeSubseq = (s) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0518.零钱兑换II.md b/problems/0518.零钱兑换II.md
index 44c00131..52ec9149 100644
--- a/problems/0518.零钱兑换II.md
+++ b/problems/0518.零钱兑换II.md
@@ -266,4 +266,4 @@ const change = (amount, coins) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0530.二叉搜索树的最小绝对差.md b/problems/0530.二叉搜索树的最小绝对差.md
index e4467178..67a81930 100644
--- a/problems/0530.二叉搜索树的最小绝对差.md
+++ b/problems/0530.二叉搜索树的最小绝对差.md
@@ -370,4 +370,4 @@ var getMinimumDifference = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0538.把二叉搜索树转换为累加树.md b/problems/0538.把二叉搜索树转换为累加树.md
index baeb300f..f2b97989 100644
--- a/problems/0538.把二叉搜索树转换为累加树.md
+++ b/problems/0538.把二叉搜索树转换为累加树.md
@@ -277,4 +277,4 @@ var convertBST = function (root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0541.反转字符串II.md b/problems/0541.反转字符串II.md
index e6939c89..26e6e847 100644
--- a/problems/0541.反转字符串II.md
+++ b/problems/0541.反转字符串II.md
@@ -282,4 +282,4 @@ func reverseStr(_ s: String, _ k: Int) -> String {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0583.两个字符串的删除操作.md b/problems/0583.两个字符串的删除操作.md
index 4935d10c..fa473062 100644
--- a/problems/0583.两个字符串的删除操作.md
+++ b/problems/0583.两个字符串的删除操作.md
@@ -211,4 +211,4 @@ const minDistance = (word1, word2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0617.合并二叉树.md b/problems/0617.合并二叉树.md
index f3b33230..8645cbc2 100644
--- a/problems/0617.合并二叉树.md
+++ b/problems/0617.合并二叉树.md
@@ -590,4 +590,4 @@ var mergeTrees = function(root1, root2) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0647.回文子串.md b/problems/0647.回文子串.md
index f2d0e7e5..cdc6b2e3 100644
--- a/problems/0647.回文子串.md
+++ b/problems/0647.回文子串.md
@@ -412,4 +412,4 @@ const countSubstrings = (s) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0649.Dota2参议院.md b/problems/0649.Dota2参议院.md
index c53262ad..41b2b361 100644
--- a/problems/0649.Dota2参议院.md
+++ b/problems/0649.Dota2参议院.md
@@ -251,4 +251,4 @@ var predictPartyVictory = function(senateStr) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0654.最大二叉树.md b/problems/0654.最大二叉树.md
index aa84c8a6..a4ae868a 100644
--- a/problems/0654.最大二叉树.md
+++ b/problems/0654.最大二叉树.md
@@ -362,4 +362,4 @@ var constructMaximumBinaryTree = function (nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0657.机器人能否返回原点.md b/problems/0657.机器人能否返回原点.md
index 4e48698e..fb35c15b 100644
--- a/problems/0657.机器人能否返回原点.md
+++ b/problems/0657.机器人能否返回原点.md
@@ -156,4 +156,4 @@ var judgeCircle = function(moves) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0669.修剪二叉搜索树.md b/problems/0669.修剪二叉搜索树.md
index ffb00b78..23269bb7 100644
--- a/problems/0669.修剪二叉搜索树.md
+++ b/problems/0669.修剪二叉搜索树.md
@@ -395,4 +395,4 @@ var trimBST = function (root,low,high) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0673.最长递增子序列的个数.md b/problems/0673.最长递增子序列的个数.md
index 13da076b..4be91db1 100644
--- a/problems/0673.最长递增子序列的个数.md
+++ b/problems/0673.最长递增子序列的个数.md
@@ -366,4 +366,4 @@ var findNumberOfLIS = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md
index 383f770e..c81155cb 100644
--- a/problems/0674.最长连续递增序列.md
+++ b/problems/0674.最长连续递增序列.md
@@ -268,4 +268,4 @@ const findLengthOfLCIS = (nums) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0684.冗余连接.md b/problems/0684.冗余连接.md
index 015c04e7..48ee6011 100644
--- a/problems/0684.冗余连接.md
+++ b/problems/0684.冗余连接.md
@@ -353,4 +353,4 @@ var findRedundantConnection = function(edges) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0685.冗余连接II.md b/problems/0685.冗余连接II.md
index c73e37aa..cbd6cc2d 100644
--- a/problems/0685.冗余连接II.md
+++ b/problems/0685.冗余连接II.md
@@ -606,4 +606,4 @@ var findRedundantDirectedConnection = function(edges) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0700.二叉搜索树中的搜索.md b/problems/0700.二叉搜索树中的搜索.md
index e4227eb1..bf67ce0e 100644
--- a/problems/0700.二叉搜索树中的搜索.md
+++ b/problems/0700.二叉搜索树中的搜索.md
@@ -342,4 +342,4 @@ var searchBST = function (root, val) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0701.二叉搜索树中的插入操作.md b/problems/0701.二叉搜索树中的插入操作.md
index 33e9999c..0d3d676b 100644
--- a/problems/0701.二叉搜索树中的插入操作.md
+++ b/problems/0701.二叉搜索树中的插入操作.md
@@ -492,4 +492,4 @@ var insertIntoBST = function (root, val) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md
index 92c23cab..e1900276 100644
--- a/problems/0704.二分查找.md
+++ b/problems/0704.二分查找.md
@@ -530,4 +530,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0707.设计链表.md b/problems/0707.设计链表.md
index 5dc9325b..64472506 100644
--- a/problems/0707.设计链表.md
+++ b/problems/0707.设计链表.md
@@ -1152,4 +1152,4 @@ class MyLinkedList {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0714.买卖股票的最佳时机含手续费.md b/problems/0714.买卖股票的最佳时机含手续费.md
index cdedd506..c6a147b4 100644
--- a/problems/0714.买卖股票的最佳时机含手续费.md
+++ b/problems/0714.买卖股票的最佳时机含手续费.md
@@ -269,4 +269,4 @@ var maxProfit = function(prices, fee) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
index d1dfeb91..8dd0894e 100644
--- a/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
+++ b/problems/0714.买卖股票的最佳时机含手续费(动态规划).md
@@ -190,4 +190,4 @@ const maxProfit = (prices,fee) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0718.最长重复子数组.md b/problems/0718.最长重复子数组.md
index d3488a06..54d1b07e 100644
--- a/problems/0718.最长重复子数组.md
+++ b/problems/0718.最长重复子数组.md
@@ -304,4 +304,4 @@ const findLength = (nums1, nums2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0724.寻找数组的中心索引.md b/problems/0724.寻找数组的中心索引.md
index 651268c2..13d2ab68 100644
--- a/problems/0724.寻找数组的中心索引.md
+++ b/problems/0724.寻找数组的中心索引.md
@@ -147,4 +147,4 @@ var pivotIndex = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md
index 70c571db..0db0db15 100644
--- a/problems/0738.单调递增的数字.md
+++ b/problems/0738.单调递增的数字.md
@@ -209,4 +209,4 @@ var monotoneIncreasingDigits = function(n) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0739.每日温度.md b/problems/0739.每日温度.md
index 5e570307..612b3c75 100644
--- a/problems/0739.每日温度.md
+++ b/problems/0739.每日温度.md
@@ -313,4 +313,4 @@ var dailyTemperatures = function(temperatures) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md
index 9e1a430e..96bfbb7c 100644
--- a/problems/0746.使用最小花费爬楼梯.md
+++ b/problems/0746.使用最小花费爬楼梯.md
@@ -272,4 +272,4 @@ var minCostClimbingStairs = function(cost) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md
index bb327db2..863b569d 100644
--- a/problems/0763.划分字母区间.md
+++ b/problems/0763.划分字母区间.md
@@ -181,4 +181,4 @@ var partitionLabels = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0841.钥匙和房间.md b/problems/0841.钥匙和房间.md
index 551ca077..42e6337f 100644
--- a/problems/0841.钥匙和房间.md
+++ b/problems/0841.钥匙和房间.md
@@ -275,4 +275,4 @@ var canVisitAllRooms = function(rooms) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0844.比较含退格的字符串.md b/problems/0844.比较含退格的字符串.md
index e0f51bd3..a60fca22 100644
--- a/problems/0844.比较含退格的字符串.md
+++ b/problems/0844.比较含退格的字符串.md
@@ -296,4 +296,4 @@ var backspaceCompare = function(s, t) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0860.柠檬水找零.md b/problems/0860.柠檬水找零.md
index 91a1450d..2e6065b4 100644
--- a/problems/0860.柠檬水找零.md
+++ b/problems/0860.柠檬水找零.md
@@ -260,4 +260,4 @@ var lemonadeChange = function(bills) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0922.按奇偶排序数组II.md b/problems/0922.按奇偶排序数组II.md
index 85549682..43046133 100644
--- a/problems/0922.按奇偶排序数组II.md
+++ b/problems/0922.按奇偶排序数组II.md
@@ -267,4 +267,4 @@ var sortArrayByParityII = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0925.长按键入.md b/problems/0925.长按键入.md
index 014b7b17..d40f619b 100644
--- a/problems/0925.长按键入.md
+++ b/problems/0925.长按键入.md
@@ -216,4 +216,4 @@ var isLongPressedName = function(name, typed) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0941.有效的山脉数组.md b/problems/0941.有效的山脉数组.md
index 9079a747..9416b309 100644
--- a/problems/0941.有效的山脉数组.md
+++ b/problems/0941.有效的山脉数组.md
@@ -173,4 +173,4 @@ var validMountainArray = function(arr) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0968.监控二叉树.md b/problems/0968.监控二叉树.md
index 579b38ab..3d698164 100644
--- a/problems/0968.监控二叉树.md
+++ b/problems/0968.监控二叉树.md
@@ -510,4 +510,4 @@ int minCameraCover(struct TreeNode* root){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md
index 12b413e1..0d9f2ac1 100644
--- a/problems/0977.有序数组的平方.md
+++ b/problems/0977.有序数组的平方.md
@@ -339,4 +339,4 @@ class Solution {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md
index 56feb20c..09e49c4f 100644
--- a/problems/1002.查找常用字符.md
+++ b/problems/1002.查找常用字符.md
@@ -339,4 +339,4 @@ func commonChars(_ words: [String]) -> [String] {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1005.K次取反后最大化的数组和.md b/problems/1005.K次取反后最大化的数组和.md
index 1d552590..1b5386fd 100644
--- a/problems/1005.K次取反后最大化的数组和.md
+++ b/problems/1005.K次取反后最大化的数组和.md
@@ -217,4 +217,4 @@ var largestSumAfterKNegations = function(nums, k) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md
index e9b03e24..f4e8f702 100644
--- a/problems/1035.不相交的线.md
+++ b/problems/1035.不相交的线.md
@@ -174,4 +174,4 @@ const maxUncrossedLines = (nums1, nums2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1047.删除字符串中的所有相邻重复项.md b/problems/1047.删除字符串中的所有相邻重复项.md
index 420b64df..f70f39f3 100644
--- a/problems/1047.删除字符串中的所有相邻重复项.md
+++ b/problems/1047.删除字符串中的所有相邻重复项.md
@@ -275,4 +275,4 @@ var removeDuplicates = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1049.最后一块石头的重量II.md b/problems/1049.最后一块石头的重量II.md
index 390e8c70..4ac80409 100644
--- a/problems/1049.最后一块石头的重量II.md
+++ b/problems/1049.最后一块石头的重量II.md
@@ -246,4 +246,4 @@ var lastStoneWeightII = function (stones) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1143.最长公共子序列.md b/problems/1143.最长公共子序列.md
index 005d333a..55083d89 100644
--- a/problems/1143.最长公共子序列.md
+++ b/problems/1143.最长公共子序列.md
@@ -221,4 +221,4 @@ const longestCommonSubsequence = (text1, text2) => {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md
index 97a66da1..a65b26e6 100644
--- a/problems/1207.独一无二的出现次数.md
+++ b/problems/1207.独一无二的出现次数.md
@@ -140,4 +140,4 @@ var uniqueOccurrences = function(arr) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1221.分割平衡字符串.md b/problems/1221.分割平衡字符串.md
index cd859418..cec49d0b 100644
--- a/problems/1221.分割平衡字符串.md
+++ b/problems/1221.分割平衡字符串.md
@@ -124,4 +124,4 @@ var balancedStringSplit = function(s) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1356.根据数字二进制下1的数目排序.md b/problems/1356.根据数字二进制下1的数目排序.md
index 953c8cfa..a122df6f 100644
--- a/problems/1356.根据数字二进制下1的数目排序.md
+++ b/problems/1356.根据数字二进制下1的数目排序.md
@@ -185,4 +185,4 @@ var sortByBits = function(arr) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1365.有多少小于当前数字的数字.md b/problems/1365.有多少小于当前数字的数字.md
index b3b6df4a..69654930 100644
--- a/problems/1365.有多少小于当前数字的数字.md
+++ b/problems/1365.有多少小于当前数字的数字.md
@@ -178,4 +178,4 @@ var smallerNumbersThanCurrent = function(nums) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/1382.将二叉搜索树变平衡.md b/problems/1382.将二叉搜索树变平衡.md
index 23084934..b7c1bec4 100644
--- a/problems/1382.将二叉搜索树变平衡.md
+++ b/problems/1382.将二叉搜索树变平衡.md
@@ -156,4 +156,4 @@ var balanceBST = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md b/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md
index e7a316fb..f9aee37f 100644
--- a/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md
+++ b/problems/O(n)的算法居然超时了,此时的n究竟是多大?.md
@@ -235,4 +235,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md b/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md
index 08841565..af2b66ae 100644
--- a/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md
+++ b/problems/为了绝杀编辑距离,卡尔做了三步铺垫.md
@@ -207,4 +207,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树中递归带着回溯.md b/problems/二叉树中递归带着回溯.md
index 6bb4ba3d..71a3ee5c 100644
--- a/problems/二叉树中递归带着回溯.md
+++ b/problems/二叉树中递归带着回溯.md
@@ -523,4 +523,4 @@ var binaryTreePaths = function(root) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树总结篇.md b/problems/二叉树总结篇.md
index 9563acf6..37696fc0 100644
--- a/problems/二叉树总结篇.md
+++ b/problems/二叉树总结篇.md
@@ -175,4 +175,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树理论基础.md b/problems/二叉树理论基础.md
index c7b316b3..b473861d 100644
--- a/problems/二叉树理论基础.md
+++ b/problems/二叉树理论基础.md
@@ -234,4 +234,4 @@ function TreeNode(val, left, right) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树的统一迭代法.md b/problems/二叉树的统一迭代法.md
index 3fa73851..19962cba 100644
--- a/problems/二叉树的统一迭代法.md
+++ b/problems/二叉树的统一迭代法.md
@@ -530,4 +530,4 @@ var postorderTraversal = function(root, res = []) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md
index ae0bc98d..6889ecc0 100644
--- a/problems/二叉树的迭代遍历.md
+++ b/problems/二叉树的迭代遍历.md
@@ -473,4 +473,4 @@ var postorderTraversal = function(root, res = []) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/二叉树的递归遍历.md b/problems/二叉树的递归遍历.md
index 06d0d39e..eee150b7 100644
--- a/problems/二叉树的递归遍历.md
+++ b/problems/二叉树的递归遍历.md
@@ -415,4 +415,4 @@ int* postorderTraversal(struct TreeNode* root, int* returnSize){
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/关于时间复杂度,你不知道的都在这里!.md b/problems/关于时间复杂度,你不知道的都在这里!.md
index 94f4bd1d..105c2b24 100644
--- a/problems/关于时间复杂度,你不知道的都在这里!.md
+++ b/problems/关于时间复杂度,你不知道的都在这里!.md
@@ -177,4 +177,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/剑指Offer05.替换空格.md b/problems/剑指Offer05.替换空格.md
index 86d6baf8..232d1a0a 100644
--- a/problems/剑指Offer05.替换空格.md
+++ b/problems/剑指Offer05.替换空格.md
@@ -313,4 +313,4 @@ func replaceSpace(_ s: String) -> String {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/剑指Offer58-II.左旋转字符串.md b/problems/剑指Offer58-II.左旋转字符串.md
index 3767c6dd..29243c6d 100644
--- a/problems/剑指Offer58-II.左旋转字符串.md
+++ b/problems/剑指Offer58-II.左旋转字符串.md
@@ -249,4 +249,4 @@ func reverseString(_ s: inout [Character], startIndex: Int, endIndex: Int) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/动态规划-股票问题总结篇.md b/problems/动态规划-股票问题总结篇.md
index b2a3e8da..899b9f6e 100644
--- a/problems/动态规划-股票问题总结篇.md
+++ b/problems/动态规划-股票问题总结篇.md
@@ -486,4 +486,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/动态规划总结篇.md b/problems/动态规划总结篇.md
index 512fad08..1f62b9df 100644
--- a/problems/动态规划总结篇.md
+++ b/problems/动态规划总结篇.md
@@ -137,4 +137,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/动态规划理论基础.md b/problems/动态规划理论基础.md
index 7a7a304b..728f0d7e 100644
--- a/problems/动态规划理论基础.md
+++ b/problems/动态规划理论基础.md
@@ -132,4 +132,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/双指针总结.md b/problems/双指针总结.md
index f5e7ba67..bea1359c 100644
--- a/problems/双指针总结.md
+++ b/problems/双指针总结.md
@@ -100,4 +100,4 @@ for (int i = 0; i < array.size(); i++) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/哈希表总结.md b/problems/哈希表总结.md
index 71100bf6..99a60585 100644
--- a/problems/哈希表总结.md
+++ b/problems/哈希表总结.md
@@ -131,4 +131,4 @@ std::unordered_map 底层实现为哈希,std::map 和std::multimap 的底层
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/哈希表理论基础.md b/problems/哈希表理论基础.md
index 331d26c8..aeb11b2e 100644
--- a/problems/哈希表理论基础.md
+++ b/problems/哈希表理论基础.md
@@ -133,4 +133,4 @@ std::unordered_map 底层实现为哈希表,std::map 和std::multimap 的底
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/回溯总结.md b/problems/回溯总结.md
index ebbcb073..421691da 100644
--- a/problems/回溯总结.md
+++ b/problems/回溯总结.md
@@ -454,4 +454,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/回溯算法去重问题的另一种写法.md b/problems/回溯算法去重问题的另一种写法.md
index cfc8ad86..8e92b95b 100644
--- a/problems/回溯算法去重问题的另一种写法.md
+++ b/problems/回溯算法去重问题的另一种写法.md
@@ -263,4 +263,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/回溯算法理论基础.md b/problems/回溯算法理论基础.md
index 286d0b77..c11200a2 100644
--- a/problems/回溯算法理论基础.md
+++ b/problems/回溯算法理论基础.md
@@ -175,4 +175,4 @@ void backtracking(参数) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/字符串总结.md b/problems/字符串总结.md
index 258ea0ef..5ac415a9 100644
--- a/problems/字符串总结.md
+++ b/problems/字符串总结.md
@@ -130,4 +130,4 @@ KMP算法是字符串查找最重要的算法,但彻底理解KMP并不容易
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/数组总结篇.md b/problems/数组总结篇.md
index 0bf90c66..3794bd45 100644
--- a/problems/数组总结篇.md
+++ b/problems/数组总结篇.md
@@ -149,4 +149,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/数组理论基础.md b/problems/数组理论基础.md
index b53665ee..15fbe9e4 100644
--- a/problems/数组理论基础.md
+++ b/problems/数组理论基础.md
@@ -124,4 +124,4 @@ public static void test_arr() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/栈与队列总结.md b/problems/栈与队列总结.md
index db8e1296..b745ea19 100644
--- a/problems/栈与队列总结.md
+++ b/problems/栈与队列总结.md
@@ -181,4 +181,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/栈与队列理论基础.md b/problems/栈与队列理论基础.md
index 8c2effec..3889b7ba 100644
--- a/problems/栈与队列理论基础.md
+++ b/problems/栈与队列理论基础.md
@@ -94,4 +94,4 @@ std::queue> third; // 定义以list为底层容器的队列
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/根据身高重建队列(vector原理讲解).md b/problems/根据身高重建队列(vector原理讲解).md
index 143ee01f..6d11fcbe 100644
--- a/problems/根据身高重建队列(vector原理讲解).md
+++ b/problems/根据身高重建队列(vector原理讲解).md
@@ -180,4 +180,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/算法模板.md b/problems/算法模板.md
index 0cf8431d..df823e81 100644
--- a/problems/算法模板.md
+++ b/problems/算法模板.md
@@ -296,4 +296,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包总结篇.md b/problems/背包总结篇.md
index 6086274e..784f8441 100644
--- a/problems/背包总结篇.md
+++ b/problems/背包总结篇.md
@@ -101,4 +101,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包理论基础01背包-1.md b/problems/背包理论基础01背包-1.md
index b2cee391..a10f92a1 100644
--- a/problems/背包理论基础01背包-1.md
+++ b/problems/背包理论基础01背包-1.md
@@ -431,4 +431,4 @@ test();
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包理论基础01背包-2.md b/problems/背包理论基础01背包-2.md
index ac551565..9bdbe8bc 100644
--- a/problems/背包理论基础01背包-2.md
+++ b/problems/背包理论基础01背包-2.md
@@ -323,4 +323,4 @@ test();
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包问题理论基础多重背包.md b/problems/背包问题理论基础多重背包.md
index 814c9711..e5eb222d 100644
--- a/problems/背包问题理论基础多重背包.md
+++ b/problems/背包问题理论基础多重背包.md
@@ -209,4 +209,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/背包问题理论基础完全背包.md b/problems/背包问题理论基础完全背包.md
index 4f3ef9ba..3420f822 100644
--- a/problems/背包问题理论基础完全背包.md
+++ b/problems/背包问题理论基础完全背包.md
@@ -349,4 +349,4 @@ function test_completePack2() {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/贪心算法总结篇.md b/problems/贪心算法总结篇.md
index a203494e..09d22da1 100644
--- a/problems/贪心算法总结篇.md
+++ b/problems/贪心算法总结篇.md
@@ -158,4 +158,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/贪心算法理论基础.md b/problems/贪心算法理论基础.md
index 495348d0..f851d66b 100644
--- a/problems/贪心算法理论基础.md
+++ b/problems/贪心算法理论基础.md
@@ -94,4 +94,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/链表总结篇.md b/problems/链表总结篇.md
index 64a7b42a..c0bc197b 100644
--- a/problems/链表总结篇.md
+++ b/problems/链表总结篇.md
@@ -98,4 +98,4 @@
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/链表理论基础.md b/problems/链表理论基础.md
index 7e0cd431..42d952c2 100644
--- a/problems/链表理论基础.md
+++ b/problems/链表理论基础.md
@@ -159,4 +159,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
diff --git a/problems/面试题02.07.链表相交.md b/problems/面试题02.07.链表相交.md
index d694899d..f283b161 100644
--- a/problems/面试题02.07.链表相交.md
+++ b/problems/面试题02.07.链表相交.md
@@ -258,4 +258,4 @@ var getIntersectionNode = function(headA, headB) {
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
+
From dc767e9f20f26e18e4dbf959134ca104f7282514 Mon Sep 17 00:00:00 2001
From: baichangfu
Date: Wed, 29 Sep 2021 13:23:21 +0800
Subject: [PATCH 181/284] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AC=94=E8=AF=AF<02?=
=?UTF-8?q?03.=E7=A7=BB=E9=99=A4=E9=93=BE=E8=A1=A8=E5=85=83=E7=B4=A0>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0203.移除链表元素.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0203.移除链表元素.md b/problems/0203.移除链表元素.md
index 61c3e8ef..82c5184c 100644
--- a/problems/0203.移除链表元素.md
+++ b/problems/0203.移除链表元素.md
@@ -40,7 +40,7 @@
**当然如果使用java ,python的话就不用手动管理内存了。**
-还要说明一下,就算使用C++来做leetcode,如果移除一个节点之后,没有手动在内存中删除这个节点,leetcode依然也是可以通过的,只不过,内存使用的空间大一些而已,但建议依然要养生手动清理内存的习惯。
+还要说明一下,就算使用C++来做leetcode,如果移除一个节点之后,没有手动在内存中删除这个节点,leetcode依然也是可以通过的,只不过,内存使用的空间大一些而已,但建议依然要养成手动清理内存的习惯。
这种情况下的移除操作,就是让节点next指针直接指向下下一个节点就可以了,
From f79ddfb2dd222a8d0ff36d6bb49dcdb83055c88b Mon Sep 17 00:00:00 2001
From: baichangfu
Date: Wed, 29 Sep 2021 16:31:06 +0800
Subject: [PATCH 182/284] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AC=94=E8=AF=AF<02?=
=?UTF-8?q?06.=E7=BF=BB=E8=BD=AC=E9=93=BE=E8=A1=A8>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0206.翻转链表.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 3814b53d..9b483484 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -27,9 +27,9 @@

-之前链表的头节点是元素1, 反转之后头结点就是元素5 ,这里并没有添加或者删除节点,仅仅是改表next指针的方向。
+之前链表的头节点是元素1, 反转之后头结点就是元素5 ,这里并没有添加或者删除节点,仅仅是改变next指针的方向。
-那么接下来看一看是如何反转呢?
+那么接下来看一看是如何反转的呢?
我们拿有示例中的链表来举例,如动画所示:
From 1ab2f9bc5b44457f6c711e6957d2e770b9570661 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Wed, 29 Sep 2021 18:24:09 +0800
Subject: [PATCH 183/284] =?UTF-8?q?Update=200042.=E6=8E=A5=E9=9B=A8?=
=?UTF-8?q?=E6=B0=B4.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python备注,和规范python代码
---
problems/0042.接雨水.md | 70 ++++++++++++++++++++++++++++++++++-------
1 file changed, 58 insertions(+), 12 deletions(-)
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index f0d0ecb3..bc397863 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -515,20 +515,66 @@ class Solution:
```python3
class Solution:
def trap(self, height: List[int]) -> int:
- st =[0]
+ # 单调栈
+ '''
+ 单调栈是按照 行 的方向来计算雨水
+ 从栈顶到栈底的顺序:从小到大
+ 通过三个元素来接水:栈顶,栈顶的下一个元素,以及即将入栈的元素
+ 雨水高度是 min(凹槽左边高度, 凹槽右边高度) - 凹槽底部高度
+ 雨水的宽度是 凹槽右边的下标 - 凹槽左边的下标 - 1(因为只求中间宽度)
+ '''
+ # stack储存index,用于计算对应的柱子高度
+ stack = [0]
result = 0
- for i in range(1,len(height)):
- while st!=[] and height[i]>height[st[-1]]:
- midh = height[st[-1]]
- st.pop()
- if st!=[]:
- hright = height[i]
- hleft = height[st[-1]]
- h = min(hright,hleft)-midh
- w = i-st[-1]-1
- result+=h*w
- st.append(i)
+ for i in range(1, len(height)):
+ # 情况一
+ if height[i] < height[stack[-1]]:
+ stack.append(i)
+
+ # 情况二
+ # 当当前柱子高度和栈顶一致时,左边的一个是不可能存放雨水的,所以保留右侧新柱子
+ # 需要使用最右边的柱子来计算宽度
+ elif height[i] == height[stack[-1]]:
+ stack.pop()
+ stack.append(i)
+
+ # 情况三
+ else:
+ # 抛出所有较低的柱子
+ while stack and height[i] > height[stack[-1]]:
+ # 栈顶就是中间的柱子:储水槽,就是凹槽的地步
+ mid_height = height[stack[-1]]
+ stack.pop()
+ if stack:
+ right_height = height[i]
+ left_height = height[stack[-1]]
+ # 两侧的较矮一方的高度 - 凹槽底部高度
+ h = min(right_height, left_height) - mid_height
+ # 凹槽右侧下标 - 凹槽左侧下标 - 1: 只求中间宽度
+ w = i - stack[-1] - 1
+ # 体积:高乘宽
+ result += h * w
+ stack.append(i)
return result
+
+# 单调栈压缩版
+class Solution:
+ def trap(self, height: List[int]) -> int:
+ stack = [0]
+ result = 0
+ for i in range(1, len(height)):
+ while stack and height[i] > height[stack[-1]]:
+ mid_height = stack.pop()
+ if stack:
+ # 雨水高度是 min(凹槽左侧高度, 凹槽右侧高度) - 凹槽底部高度
+ h = min(height[stack[-1]], height[i]) - height[mid_height]
+ # 雨水宽度是 凹槽右侧的下标 - 凹槽左侧的下标 - 1
+ w = i - stack[-1] - 1
+ # 累计总雨水体积
+ result += h * w
+ stack.append(i)
+ return result
+
```
Go:
From 5a37bed1354caa491af686bb3a40ffe7ba94c983 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Thu, 30 Sep 2021 16:32:53 +0800
Subject: [PATCH 184/284] =?UTF-8?q?Update=200084.=E6=9F=B1=E7=8A=B6?=
=?UTF-8?q?=E5=9B=BE=E4=B8=AD=E6=9C=80=E5=A4=A7=E7=9A=84=E7=9F=A9=E5=BD=A2?=
=?UTF-8?q?.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补全所有python解法,补充comment
---
problems/0084.柱状图中最大的矩形.md | 161 +++++++++++++++++++++-------
1 file changed, 123 insertions(+), 38 deletions(-)
diff --git a/problems/0084.柱状图中最大的矩形.md b/problems/0084.柱状图中最大的矩形.md
index ccb59fbe..427c23b9 100644
--- a/problems/0084.柱状图中最大的矩形.md
+++ b/problems/0084.柱状图中最大的矩形.md
@@ -281,52 +281,137 @@ class Solution {
Python:
-动态规划
```python3
+
+# 双指针;暴力解法(leetcode超时)
class Solution:
def largestRectangleArea(self, heights: List[int]) -> int:
- result = 0
- minleftindex, minrightindex = [0]*len(heights), [0]*len(heights)
-
- minleftindex[0]=-1
- for i in range(1,len(heights)):
- t = i-1
- while t>=0 and heights[t]>=heights[i]: t=minleftindex[t]
- minleftindex[i]=t
-
- minrightindex[-1]=len(heights)
- for i in range(len(heights)-2,-1,-1):
- t=i+1
- while t=heights[i]: t=minrightindex[t]
- minrightindex[i]=t
-
- for i in range(0,len(heights)):
- left = minleftindex[i]
- right = minrightindex[i]
- summ = (right-left-1)*heights[i]
- result = max(result,summ)
- return result
-```
-单调栈 版本二
-```python3
+ # 从左向右遍历:以每一根柱子为主心骨(当前轮最高的参照物),迭代直到找到左侧和右侧各第一个矮一级的柱子
+ res = 0
+
+ for i in range(len(heights)):
+ left = i
+ right = i
+ # 向左侧遍历:寻找第一个矮一级的柱子
+ for _ in range(left, -1, -1):
+ if heights[left] < heights[i]:
+ break
+ left -= 1
+ # 向右侧遍历:寻找第一个矮一级的柱子
+ for _ in range(right, len(heights)):
+ if heights[right] < heights[i]:
+ break
+ right += 1
+
+ width = right - left - 1
+ height = heights[i]
+ res = max(res, width * height)
+
+ return res
+
+# DP动态规划
class Solution:
def largestRectangleArea(self, heights: List[int]) -> int:
- heights.insert(0,0) # 数组头部加入元素0
- heights.append(0) # 数组尾部加入元素0
- st = [0]
+ size = len(heights)
+ # 两个DP数列储存的均是下标index
+ min_left_index = [0] * size
+ min_right_index = [0] * size
result = 0
- for i in range(1,len(heights)):
- while st!=[] and heights[i]= 0 and heights[temp] >= heights[i]:
+ # 当左侧的柱子持续较高时,尝试这个高柱子自己的次级柱子(DP
+ temp = min_left_index[temp]
+ # 当找到左侧矮一级的目标柱子时
+ min_left_index[i] = temp
+
+ # 记录每个柱子的右侧第一个矮一级的柱子的下标
+ min_right_index[size-1] = size # 初始化防止while死循环
+ for i in range(size-2, -1, -1):
+ # 以当前柱子为主心骨,向右迭代寻找次级柱子
+ temp = i + 1
+ while temp < size and heights[temp] >= heights[i]:
+ # 当右侧的柱子持续较高时,尝试这个高柱子自己的次级柱子(DP
+ temp = min_right_index[temp]
+ # 当找到右侧矮一级的目标柱子时
+ min_right_index[i] = temp
+
+ for i in range(size):
+ area = heights[i] * (min_right_index[i] - min_left_index[i] - 1)
+ result = max(area, result)
+
return result
+
+# 单调栈
+class Solution:
+ def largestRectangleArea(self, heights: List[int]) -> int:
+ # Monotonic Stack
+ '''
+ 找每个柱子左右侧的第一个高度值小于该柱子的柱子
+ 单调栈:栈顶到栈底:从大到小(每插入一个新的小数值时,都要弹出先前的大数值)
+ 栈顶,栈顶的下一个元素,即将入栈的元素:这三个元素组成了最大面积的高度和宽度
+ 情况一:当前遍历的元素heights[i]大于栈顶元素的情况
+ 情况二:当前遍历的元素heights[i]等于栈顶元素的情况
+ 情况三:当前遍历的元素heights[i]小于栈顶元素的情况
+ '''
+
+ # 输入数组首尾各补上一个0(与42.接雨水不同的是,本题原首尾的两个柱子可以作为核心柱进行最大面积尝试
+ heights.insert(0, 0)
+ heights.append(0)
+ stack = [0]
+ result = 0
+ for i in range(1, len(heights)):
+ # 情况一
+ if heights[i] > heights[stack[-1]]:
+ stack.append(i)
+ # 情况二
+ elif heights[i] == heights[stack[-1]]:
+ stack.pop()
+ stack.append(i)
+ # 情况三
+ else:
+ # 抛出所有较高的柱子
+ while stack and heights[i] < heights[stack[-1]]:
+ # 栈顶就是中间的柱子,主心骨
+ mid_index = stack[-1]
+ stack.pop()
+ if stack:
+ left_index = stack[-1]
+ right_index = i
+ width = right_index - left_index - 1
+ height = heights[mid_index]
+ result = max(result, width * height)
+ stack.append(i)
+ return result
+
+# 单调栈精简
+class Solution:
+ def largestRectangleArea(self, heights: List[int]) -> int:
+ heights.insert(0, 0)
+ heights.append(0)
+ stack = [0]
+ result = 0
+ for i in range(1, len(heights)):
+ while stack and heights[i] < heights[stack[-1]]:
+ mid_height = heights[stack[-1]]
+ stack.pop()
+ if stack:
+ # area = width * height
+ area = (i - stack[-1] - 1) * mid_height
+ result = max(area, result)
+ stack.append(i)
+ return result
+
+
+
+
+
```
+*****
JavaScript:
```javascript
From 3c3f8a883e6456c54e3dda207ba91aec1b9f61a6 Mon Sep 17 00:00:00 2001
From: 0x404 <871206929@qq.com>
Date: Fri, 1 Oct 2021 13:51:39 +0800
Subject: [PATCH 185/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E376.=E6=91=86?=
=?UTF-8?q?=E5=8A=A8=E5=BA=8F=E5=88=97=20=E5=8A=A8=E6=80=81=E8=A7=84?=
=?UTF-8?q?=E5=88=92=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0376.摆动序列.md | 66 +++++++++++++++++++++++++++++++++++++--
1 file changed, 64 insertions(+), 2 deletions(-)
diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md
index 23348bd0..7da39526 100644
--- a/problems/0376.摆动序列.md
+++ b/problems/0376.摆动序列.md
@@ -33,8 +33,7 @@
输入: [1,2,3,4,5,6,7,8,9]
输出: 2
-
-## 思路
+## 思路1(贪心解法)
本题要求通过从原始序列中删除一些(也可以不删除)元素来获得子序列,剩下的元素保持其原始顺序。
@@ -93,6 +92,69 @@ public:
时间复杂度O(n)
空间复杂度O(1)
+## 思路2(动态规划)
+
+考虑用动态规划的思想来解决这个问题。
+
+很容易可以发现,对于我们当前考虑的这个数,要么是作为山峰(即nums[i] > nums[i-1]),要么是作为山谷(即nums[i] < nums[i - 1])。
+
+* 设dp状态`dp[i][0]`,表示考虑前i个数,第i个数作为山峰的摆动子序列的最长长度
+* 设dp状态`dp[i][1]`,表示考虑前i个数,第i个数作为山谷的摆动子序列的最长长度
+
+则转移方程为:
+
+* `dp[i][0] = max(dp[i][0], dp[j][1] + 1)`,其中`0 < j < i`且`nums[j] < nums[i]`,表示将nums[i]接到前面某个山谷后面,作为山峰。
+* `dp[i][1] = max(dp[i][1], dp[j][0] + 1)`,其中`0 < j < i`且`nums[j] > nums[i]`,表示将nums[i]接到前面某个山峰后面,作为山谷。
+
+初始状态:
+
+由于一个数可以接到前面的某个数后面,也可以以自身为子序列的起点,所以初始状态为:`dp[0][0] = dp[0][1] = 1`。
+
+C++代码如下:
+
+```c++
+class Solution {
+public:
+ int dp[1005][2];
+ int wiggleMaxLength(vector& nums) {
+ memset(dp, 0, sizeof dp);
+ dp[0][0] = dp[0][1] = 1;
+
+ for (int i = 1; i < nums.size(); ++i)
+ {
+ dp[i][0] = dp[i][1] = 1;
+
+ for (int j = 0; j < i; ++j)
+ {
+ if (nums[j] > nums[i]) dp[i][1] = max(dp[i][1], dp[j][0] + 1);
+ }
+
+ for (int j = 0; j < i; ++j)
+ {
+ if (nums[j] < nums[i]) dp[i][0] = max(dp[i][0], dp[j][1] + 1);
+ }
+ }
+ return max(dp[nums.size() - 1][0], dp[nums.size() - 1][1]);
+ }
+};
+```
+
+时间复杂度O(n^2)
+
+空间复杂度O(n)
+
+**进阶**
+
+可以用两棵线段树来维护区间的最大值
+
+* 每次更新`dp[i][0]`,则在`tree1`的`nums[i]`位置值更新为`dp[i][0]`
+* 每次更新`dp[i][1]`,则在`tree2`的`nums[i]`位置值更新为`dp[i][1]`
+* 则dp转移方程中就没有必要j从0遍历到i-1,可以直接在线段树中查询指定区间的值即可。
+
+时间复杂度O(nlogn)
+
+空间复杂度O(n)
+
## 总结
**贪心的题目说简单有的时候就是常识,说难就难在都不知道该怎么用贪心**。
From b8f4d4f6c987b778f1580dc0c3ef799a5dfe205b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98Carl?=
Date: Fri, 1 Oct 2021 19:05:09 +0800
Subject: [PATCH 186/284] =?UTF-8?q?Update=20=E6=95=B0=E7=BB=84=E6=80=BB?=
=?UTF-8?q?=E7=BB=93=E7=AF=87.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/数组总结篇.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/数组总结篇.md b/problems/数组总结篇.md
index 528904c2..aa2ae5fb 100644
--- a/problems/数组总结篇.md
+++ b/problems/数组总结篇.md
@@ -51,7 +51,7 @@
-所以**二维数据在内存中不是 `3*4` 的连续地址空间,而是三条连续的地址空间组成!**
+所以**二维数据在内存中不是 `3*4` 的连续地址空间,而是四条连续的地址空间组成!**
# 数组的经典题目
From 8880fb9a657c27304f9ef0a3e6f5d119356d6781 Mon Sep 17 00:00:00 2001
From: Arthur
Date: Fri, 1 Oct 2021 15:15:45 +0100
Subject: [PATCH 187/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A00046.=E5=85=A8?=
=?UTF-8?q?=E6=8E=92=E5=88=97.md=20C=E8=AF=AD=E8=A8=80=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0046.全排列.md | 66 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md
index 001c249e..f41c2509 100644
--- a/problems/0046.全排列.md
+++ b/problems/0046.全排列.md
@@ -309,6 +309,72 @@ var permute = function(nums) {
```
+C:
+```c
+int* path;
+int pathTop;
+int** ans;
+int ansTop;
+
+//将used中元素都设置为0
+void initialize(int* used, int usedLength) {
+ int i;
+ for(i = 0; i < usedLength; i++) {
+ used[i] = 0;
+ }
+}
+
+//将path中元素拷贝到ans中
+void copy() {
+ int* tempPath = (int*)malloc(sizeof(int) * pathTop);
+ int i;
+ for(i = 0; i < pathTop; i++) {
+ tempPath[i] = path[i];
+ }
+ ans[ansTop++] = tempPath;
+}
+
+void backTracking(int* nums, int numsSize, int* used) {
+ //若path中元素个数等于nums元素个数,将nums放入ans中
+ if(pathTop == numsSize) {
+ copy();
+ return;
+ }
+ int i;
+ for(i = 0; i < numsSize; i++) {
+ //若当前下标中元素已使用过,则跳过当前元素
+ if(used[i])
+ continue;
+ used[i] = 1;
+ path[pathTop++] = nums[i];
+ backTracking(nums, numsSize, used);
+ //回溯
+ pathTop--;
+ used[i] = 0;
+ }
+}
+
+int** permute(int* nums, int numsSize, int* returnSize, int** returnColumnSizes){
+ //初始化辅助变量
+ path = (int*)malloc(sizeof(int) * numsSize);
+ ans = (int**)malloc(sizeof(int*) * 1000);
+ int* used = (int*)malloc(sizeof(int) * numsSize);
+ //将used数组中元素都置0
+ initialize(used, numsSize);
+ ansTop = pathTop = 0;
+
+ backTracking(nums, numsSize, used);
+
+ //设置path和ans数组的长度
+ *returnSize = ansTop;
+ *returnColumnSizes = (int*)malloc(sizeof(int) * ansTop);
+ int i;
+ for(i = 0; i < ansTop; i++) {
+ (*returnColumnSizes)[i] = numsSize;
+ }
+ return ans;
+}
+```
-----------------------
From 78225288cf29223a5e2c7563a0a2cfa72da3fb6f Mon Sep 17 00:00:00 2001
From: hailincai
Date: Fri, 1 Oct 2021 14:16:45 -0400
Subject: [PATCH 188/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0java=E7=89=88?=
=?UTF-8?q?=E6=9C=AC---=E5=88=86=E5=89=B2=E5=B9=B3=E8=A1=A1=E5=AD=97?=
=?UTF-8?q?=E7=AC=A6=E4=B8=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add java implementation
---
problems/1221.分割平衡字符串.md | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/problems/1221.分割平衡字符串.md b/problems/1221.分割平衡字符串.md
index cec49d0b..bc1f1fc4 100644
--- a/problems/1221.分割平衡字符串.md
+++ b/problems/1221.分割平衡字符串.md
@@ -93,6 +93,18 @@ public:
## Java
```java
+class Solution {
+ public int balancedStringSplit(String s) {
+ int result = 0;
+ int count = 0;
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'R') count++;
+ else count--;
+ if (count == 0) result++;
+ }
+ return result;
+ }
+}
```
## Python
From dd21fc7a11715bccaeb7f6da11a4bec4016ecf6e Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Sat, 2 Oct 2021 10:29:57 +0800
Subject: [PATCH 189/284] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=200376=20=E6=91=86?=
=?UTF-8?q?=E5=8A=A8=E5=BA=8F=E5=88=97=20JavaScript=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=8C=BA=E9=97=B4=E9=94=99=E8=AF=AF=20?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
原代码中 存在 区间超出范围问题, 现给出修改方案
---
problems/0376.摆动序列.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md
index 23348bd0..82b67451 100644
--- a/problems/0376.摆动序列.md
+++ b/problems/0376.摆动序列.md
@@ -177,7 +177,7 @@ var wiggleMaxLength = function(nums) {
let result = 1
let preDiff = 0
let curDiff = 0
- for(let i = 0; i <= nums.length; i++) {
+ for(let i = 0; i < nums.length - 1; i++) {
curDiff = nums[i + 1] - nums[i]
if((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)) {
result++
From 0b48719c49b6184eac214d80a08a7556238038e5 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Sat, 2 Oct 2021 13:47:57 +0800
Subject: [PATCH 190/284] =?UTF-8?q?=E8=A7=A3=E5=86=B3=200435=20=E6=97=A0?=
=?UTF-8?q?=E9=87=8D=E5=8F=A0=E5=8C=BA=E9=97=B4=20C++=20=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0435.无重叠区间.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md
index 79083716..830f0c7e 100644
--- a/problems/0435.无重叠区间.md
+++ b/problems/0435.无重叠区间.md
@@ -72,7 +72,7 @@
C++代码如下:
-```
+```c++
class Solution {
public:
// 按照区间右边界排序
From ef2eb4b47ab282737b8344bb4837aeb5b066dbcf Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Sat, 2 Oct 2021 14:02:38 +0800
Subject: [PATCH 191/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E=200056=20=E5=90=88?=
=?UTF-8?q?=E5=B9=B6=E5=8C=BA=E9=97=B4=20JavaScript=20=E5=8F=A6=E4=B8=80?=
=?UTF-8?q?=E7=A7=8D=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0056.合并区间.md | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/problems/0056.合并区间.md b/problems/0056.合并区间.md
index 93c0a2a0..fd914497 100644
--- a/problems/0056.合并区间.md
+++ b/problems/0056.合并区间.md
@@ -241,6 +241,32 @@ var merge = function (intervals) {
return result
};
```
+版本二:左右区间
+```javascript
+/**
+ * @param {number[][]} intervals
+ * @return {number[][]}
+ */
+var merge = function(intervals) {
+ let n = intervals.length;
+ if ( n < 2) return intervals;
+ intervals.sort((a, b) => a[0]- b[0]);
+ let res = [],
+ left = intervals[0][0],
+ right = intervals[0][1];
+ for (let i = 1; i < n; i++) {
+ if (intervals[i][0] > right) {
+ res.push([left, right]);
+ left = intervals[i][0];
+ right = intervals[i][1];
+ } else {
+ right = Math.max(intervals[i][1], right);
+ }
+ }
+ res.push([left, right]);
+ return res;
+};
+```
From ee3e483505af9c53fb1e374bd0de9647f6e9b729 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Sat, 2 Oct 2021 14:19:52 +0800
Subject: [PATCH 192/284] =?UTF-8?q?=E8=A1=A5=E5=85=85=200714=20=E4=B9=B0?=
=?UTF-8?q?=E5=8D=96=E8=82=A1=E7=A5=A8=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA?=
=?UTF-8?q?=E5=90=AB=E6=89=8B=E7=BB=AD=E8=B4=B9=20JavaScript=20=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=20=E5=8A=A8=E6=80=81=E8=A7=84=E5=88=92=E8=A7=A3?=
=?UTF-8?q?=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0714.买卖股票的最佳时机含手续费.md | 28 +++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/problems/0714.买卖股票的最佳时机含手续费.md b/problems/0714.买卖股票的最佳时机含手续费.md
index c6a147b4..576f5f85 100644
--- a/problems/0714.买卖股票的最佳时机含手续费.md
+++ b/problems/0714.买卖股票的最佳时机含手续费.md
@@ -262,6 +262,34 @@ var maxProfit = function(prices, fee) {
}
return result
};
+
+// 动态规划
+/**
+ * @param {number[]} prices
+ * @param {number} fee
+ * @return {number}
+ */
+var maxProfit = function(prices, fee) {
+ // 滚动数组
+ // have表示当天持有股票的最大收益
+ // notHave表示当天不持有股票的最大收益
+ // 把手续费算在买入价格中
+ let n = prices.length,
+ have = -prices[0]-fee, // 第0天持有股票的最大收益
+ notHave = 0; // 第0天不持有股票的最大收益
+ for (let i = 1; i < n; i++) {
+ // 第i天持有股票的最大收益由两种情况组成
+ // 1、第i-1天就已经持有股票,第i天什么也没做
+ // 2、第i-1天不持有股票,第i天刚买入
+ have = Math.max(have, notHave - prices[i] - fee);
+ // 第i天不持有股票的最大收益由两种情况组成
+ // 1、第i-1天就已经不持有股票,第i天什么也没做
+ // 2、第i-1天持有股票,第i天刚卖出
+ notHave = Math.max(notHave, have + prices[i]);
+ }
+ // 最后手中不持有股票,收益才能最大化
+ return notHave;
+};
```
From 35d30c93dd7c18893c77f96b9c1daa6b58649ac3 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Sun, 3 Oct 2021 10:33:51 +0800
Subject: [PATCH 193/284] =?UTF-8?q?=E6=96=B0=E5=A2=9E=200062=20=E4=B8=8D?=
=?UTF-8?q?=E5=90=8C=E8=B7=AF=E5=BE=84=20JavaScript=E7=89=88=E6=9C=AC=20?=
=?UTF-8?q?=E5=8F=A6=E4=B8=80=E7=A7=8D=E5=86=99=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
我认为将dp数组的值全部初始化为1是可以的,因为由状态转移方程:dp[i][j] = dp[i-1][j] + dp[i][j-1] 可知,当前dp[i][j]的值与其自身的原始值并无联系。所有将dp的所有值都初始化为1,可以减少代码量,同时也不会影响代码的整体思路。
---
problems/0062.不同路径.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/problems/0062.不同路径.md b/problems/0062.不同路径.md
index af3a8f40..31896fd1 100644
--- a/problems/0062.不同路径.md
+++ b/problems/0062.不同路径.md
@@ -327,6 +327,25 @@ var uniquePaths = function(m, n) {
return dp[m - 1][n - 1]
};
```
+>版本二:直接将dp数值值初始化为1
+```javascript
+/**
+ * @param {number} m
+ * @param {number} n
+ * @return {number}
+ */
+var uniquePaths = function(m, n) {
+ let dp = new Array(m).fill(1).map(() => new Array(n).fill(1));
+ // dp[i][j] 表示到达(i,j) 点的路径数
+ for (let i=1; i
Date: Sun, 3 Oct 2021 18:59:22 +0800
Subject: [PATCH 194/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200206.=E7=BF=BB?=
=?UTF-8?q?=E8=BD=AC=E9=93=BE=E8=A1=A8.md=20=E6=B7=BB=E5=8A=A0=E9=80=92?=
=?UTF-8?q?=E5=BD=92=E8=A7=A3=E6=B3=95=E6=80=9D=E8=B7=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0206.翻转链表.md | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index ef2664eb..0a8b3622 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -96,6 +96,26 @@ public:
};
```
+我们可以发现,上面的递归写法和双指针法实质上都是从前往后翻转指针指向,其实还有另外一种与双指针法不同思路的递归写法:从后往前翻转指针指向。
+
+具体代码如下(带详细注释):
+
+```c++
+class Solution {
+public:
+ ListNode* reverseList(ListNode* head) {
+ // 如果链表只有一个节点,返回自身
+ if (head->next == NULL) return head;
+ // 递归调用,翻转第二个节点开始往后的链表
+ ListNode *last = reverseList(head->next);
+ // 翻转头节点与第二个节点的指向
+ head->next->next = head;
+ // 此时的 head 节点为尾节点,next 需要指向 NULL
+ head->next = NULL;
+ return last;
+ }
+};
+```
## 其他语言版本
From 8b6346c4e8d02a68f953a9f350376d68ac9d42eb Mon Sep 17 00:00:00 2001
From: Evan Yang
Date: Sun, 3 Oct 2021 19:07:45 +0800
Subject: [PATCH 195/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200206.=E7=BF=BB?=
=?UTF-8?q?=E8=BD=AC=E9=93=BE=E8=A1=A8.md=20=E4=BF=AE=E5=A4=8DJava?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=E9=80=92=E5=BD=92=E5=86=99=E6=B3=95=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0206.翻转链表.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 0a8b3622..4e450a1b 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -155,9 +155,9 @@ class Solution {
temp = cur.next;// 先保存下一个节点
cur.next = prev;// 反转
// 更新prev、cur位置
- prev = cur;
- cur = temp;
- return reverse(prev, cur);
+ // prev = cur;
+ // cur = temp;
+ return reverse(cur, temp);
}
}
```
From 0ff89f039dd1b6444e4f0ae0d3fd0477ab271812 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 3 Oct 2021 19:19:31 +0800
Subject: [PATCH 196/284] =?UTF-8?q?Update=200110.=E5=B9=B3=E8=A1=A1?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
纠正笔误深度和高度
---
problems/0110.平衡二叉树.md | 100 +++++++++++++++++++++---------------
1 file changed, 58 insertions(+), 42 deletions(-)
diff --git a/problems/0110.平衡二叉树.md b/problems/0110.平衡二叉树.md
index 7858fa60..41cf1ef7 100644
--- a/problems/0110.平衡二叉树.md
+++ b/problems/0110.平衡二叉树.md
@@ -125,9 +125,10 @@ public:
1. 明确递归函数的参数和返回值
-参数的话为传入的节点指针,就没有其他参数需要传递了,返回值要返回传入节点为根节点树的深度。
+参数:当前传入节点。
+返回值:以当前传入节点为根节点的树的高度。
-那么如何标记左右子树是否差值大于1呢。
+那么如何标记左右子树是否差值大于1呢?
如果当前传入节点为根节点的二叉树已经不是二叉平衡树了,还返回高度的话就没有意义了。
@@ -136,9 +137,9 @@ public:
代码如下:
-```
+```CPP
// -1 表示已经不是平衡二叉树了,否则返回值是以该节点为根节点树的高度
-int getDepth(TreeNode* node)
+int getHeight(TreeNode* node)
```
2. 明确终止条件
@@ -147,7 +148,7 @@ int getDepth(TreeNode* node)
代码如下:
-```
+```CPP
if (node == NULL) {
return 0;
}
@@ -155,23 +156,23 @@ if (node == NULL) {
3. 明确单层递归的逻辑
-如何判断当前传入节点为根节点的二叉树是否是平衡二叉树呢,当然是左子树高度和右子树高度相差。
+如何判断以当前传入节点为根节点的二叉树是否是平衡二叉树呢?当然是其左子树高度和其右子树高度的差值。
-分别求出左右子树的高度,然后如果差值小于等于1,则返回当前二叉树的高度,否则则返回-1,表示已经不是二叉树了。
+分别求出其左右子树的高度,然后如果差值小于等于1,则返回当前二叉树的高度,否则则返回-1,表示已经不是二叉平衡树了。
代码如下:
```CPP
-int leftDepth = depth(node->left); // 左
-if (leftDepth == -1) return -1;
-int rightDepth = depth(node->right); // 右
-if (rightDepth == -1) return -1;
+int leftHeight = getHeight(node->left); // 左
+if (leftHeight == -1) return -1;
+int rightHeight = getHeight(node->right); // 右
+if (rightHeight == -1) return -1;
int result;
-if (abs(leftDepth - rightDepth) > 1) { // 中
+if (abs(leftHeight - rightHeight) > 1) { // 中
result = -1;
} else {
- result = 1 + max(leftDepth, rightDepth); // 以当前节点为根节点的最大高度
+ result = 1 + max(leftHeight, rightHeight); // 以当前节点为根节点的树的最大高度
}
return result;
@@ -180,27 +181,27 @@ return result;
代码精简之后如下:
```CPP
-int leftDepth = getDepth(node->left);
-if (leftDepth == -1) return -1;
-int rightDepth = getDepth(node->right);
-if (rightDepth == -1) return -1;
-return abs(leftDepth - rightDepth) > 1 ? -1 : 1 + max(leftDepth, rightDepth);
+int leftHeight = getHeight(node->left);
+if (leftHeight == -1) return -1;
+int rightHeight = getHeight(node->right);
+if (rightHeight == -1) return -1;
+return abs(leftHeight - rightHeight) > 1 ? -1 : 1 + max(leftHeight, rightHeight);
```
此时递归的函数就已经写出来了,这个递归的函数传入节点指针,返回以该节点为根节点的二叉树的高度,如果不是二叉平衡树,则返回-1。
-getDepth整体代码如下:
+getHeight整体代码如下:
```CPP
-int getDepth(TreeNode* node) {
+int getHeight(TreeNode* node) {
if (node == NULL) {
return 0;
}
- int leftDepth = getDepth(node->left);
- if (leftDepth == -1) return -1;
- int rightDepth = getDepth(node->right);
- if (rightDepth == -1) return -1;
- return abs(leftDepth - rightDepth) > 1 ? -1 : 1 + max(leftDepth, rightDepth);
+ int leftHeight = getHeight(node->left);
+ if (leftHeight == -1) return -1;
+ int rightHeight = getHeight(node->right);
+ if (rightHeight == -1) return -1;
+ return abs(leftHeight - rightHeight) > 1 ? -1 : 1 + max(leftHeight, rightHeight);
}
```
@@ -210,18 +211,18 @@ int getDepth(TreeNode* node) {
class Solution {
public:
// 返回以该节点为根节点的二叉树的高度,如果不是二叉搜索树了则返回-1
- int getDepth(TreeNode* node) {
+ int getHeight(TreeNode* node) {
if (node == NULL) {
return 0;
}
- int leftDepth = getDepth(node->left);
- if (leftDepth == -1) return -1; // 说明左子树已经不是二叉平衡树
- int rightDepth = getDepth(node->right);
- if (rightDepth == -1) return -1; // 说明右子树已经不是二叉平衡树
- return abs(leftDepth - rightDepth) > 1 ? -1 : 1 + max(leftDepth, rightDepth);
+ int leftHeight = getHeight(node->left);
+ if (leftHeight == -1) return -1;
+ int rightHeight = getHeight(node->right);
+ if (rightHeight == -1) return -1;
+ return abs(leftHeight - rightHeight) > 1 ? -1 : 1 + max(leftHeight, rightHeight);
}
bool isBalanced(TreeNode* root) {
- return getDepth(root) == -1 ? false : true;
+ return getHeight(root) == -1 ? false : true;
}
};
```
@@ -498,20 +499,35 @@ class Solution {
## Python
递归法:
-```python
+```python3
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
def isBalanced(self, root: TreeNode) -> bool:
- return True if self.getDepth(root) != -1 else False
+ if self.get_height(root) != -1:
+ return True
+ else:
+ return False
- #返回以该节点为根节点的二叉树的高度,如果不是二叉搜索树了则返回-1
- def getDepth(self, node):
- if not node:
+ def get_height(self, root: TreeNode) -> int:
+ # Base Case
+ if not root:
return 0
- leftDepth = self.getDepth(node.left)
- if leftDepth == -1: return -1 #说明左子树已经不是二叉平衡树
- rightDepth = self.getDepth(node.right)
- if rightDepth == -1: return -1 #说明右子树已经不是二叉平衡树
- return -1 if abs(leftDepth - rightDepth)>1 else 1 + max(leftDepth, rightDepth)
+ # 左
+ if (left_height := self.get_height(root.left)) == -1:
+ return -1
+ # 右
+ if (right_height := self.get_height(root.right)) == -1:
+ return -1
+ # 中
+ if abs(left_height - right_height) > 1:
+ return -1
+ else:
+ return 1 + max(left_height, right_height)
```
迭代法:
From dab89905adaac01f541ecb71f2a9e30980c88249 Mon Sep 17 00:00:00 2001
From: Evan Yang
Date: Sun, 3 Oct 2021 19:21:53 +0800
Subject: [PATCH 197/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200206.=E7=BF=BB?=
=?UTF-8?q?=E8=BD=AC=E9=93=BE=E8=A1=A8.md=20=E6=B7=BB=E5=8A=A0=E9=80=92?=
=?UTF-8?q?=E5=BD=92=E8=A7=A3=E6=B3=95=E6=80=9D=E8=B7=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0206.翻转链表.md | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 4e450a1b..0c35f7d7 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -104,8 +104,10 @@ public:
class Solution {
public:
ListNode* reverseList(ListNode* head) {
- // 如果链表只有一个节点,返回自身
+ // 边缘条件判断
+ if(head == NULL) return NULL;
if (head->next == NULL) return head;
+
// 递归调用,翻转第二个节点开始往后的链表
ListNode *last = reverseList(head->next);
// 翻转头节点与第二个节点的指向
From f1aa928e1cc8349a26b3ceb37184a6216f272736 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 3 Oct 2021 20:09:23 +0800
Subject: [PATCH 198/284] =?UTF-8?q?Update=200257.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E7=9A=84=E6=89=80=E6=9C=89=E8=B7=AF=E5=BE=84.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修订python3语法规范lint
---
problems/0257.二叉树的所有路径.md | 43 +++++++++++++++++++------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md
index c85186d5..f902aab2 100644
--- a/problems/0257.二叉树的所有路径.md
+++ b/problems/0257.二叉树的所有路径.md
@@ -404,33 +404,41 @@ class Solution {
}
}
```
-
-Python:
-```Python
+---
+Python:
+递归法+隐形回溯
+```Python3
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
- """二叉树的所有路径 递归法"""
-
def binaryTreePaths(self, root: TreeNode) -> List[str]:
- path, result = '', []
+ path = ''
+ result = []
+ if not root: return result
self.traversal(root, path, result)
return result
- def traversal(self, cur: TreeNode, path: List, result: List):
+ def traversal(self, cur: TreeNode, path: str, result: List[str]) -> None:
path += str(cur.val)
- # 如果当前节点为叶子节点,添加路径到结果中
- if not (cur.left or cur.right):
+ # 若当前节点为leave,直接输出
+ if not cur.left and not cur.right:
result.append(path)
- return
-
+
if cur.left:
+ # + '->' 是隐藏回溯
self.traversal(cur.left, path + '->', result)
-
+
if cur.right:
self.traversal(cur.right, path + '->', result)
-
```
-
-```python
+
+迭代法:
+
+```python3
from collections import deque
@@ -457,7 +465,8 @@ class Solution:
return result
```
-
+
+---
Go:
```go
@@ -482,7 +491,7 @@ func binaryTreePaths(root *TreeNode) []string {
return res
}
```
-
+---
JavaScript:
1.递归版本
From 5570ce5aafad0583fab8dc5e0b77c824870a557b Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Mon, 4 Oct 2021 09:05:35 +0800
Subject: [PATCH 199/284] =?UTF-8?q?=E8=A7=A3=E5=86=B3=200416=20=E5=88=86?=
=?UTF-8?q?=E5=89=B2=E7=AD=89=E5=92=8C=E5=AD=90=E9=9B=86=20Go=20=E8=AF=AD?=
=?UTF-8?q?=E8=A8=80=E7=89=88=E6=9C=AC=E4=BB=A3=E7=A0=81=E6=B2=A1=E6=9C=89?=
=?UTF-8?q?=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0416.分割等和子集.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0416.分割等和子集.md b/problems/0416.分割等和子集.md
index fd20f68a..05c272c6 100644
--- a/problems/0416.分割等和子集.md
+++ b/problems/0416.分割等和子集.md
@@ -227,7 +227,7 @@ class Solution:
```
Go:
-```
+```go
func canPartition(nums []int) bool {
/**
动态五部曲:
From af819a97267fdf154dea9367425efddfce793757 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Mon, 4 Oct 2021 09:21:46 +0800
Subject: [PATCH 200/284] =?UTF-8?q?=E5=88=A0=E9=99=A4=200494=20=E7=9B=AE?=
=?UTF-8?q?=E6=A0=87=E5=92=8C=20JavaScript=E7=89=88=E6=9C=AC=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E4=B8=AD=E7=9A=84=E6=8E=92=E5=BA=8F=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
对原数组升序排序是没有必要的
---
problems/0494.目标和.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/problems/0494.目标和.md b/problems/0494.目标和.md
index 210ac749..00771c22 100644
--- a/problems/0494.目标和.md
+++ b/problems/0494.目标和.md
@@ -371,7 +371,6 @@ const findTargetSumWays = (nums, target) => {
}
const halfSum = (target + sum) / 2;
- nums.sort((a, b) => a - b);
let dp = new Array(halfSum+1).fill(0);
dp[0] = 1;
From 5ecfb3aaca49e37520f53249028a8fcf324a1a7f Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Mon, 4 Oct 2021 09:43:48 +0800
Subject: [PATCH 201/284] =?UTF-8?q?=E8=A7=A3=E5=86=B3=200070=20=E7=88=AC?=
=?UTF-8?q?=E6=A5=BC=E6=A2=AF=20c++=E4=BB=A3=E7=A0=81=E6=B2=A1=E6=9C=89?=
=?UTF-8?q?=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0070.爬楼梯完全背包版本.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md
index 104b2d5a..3851e7a5 100644
--- a/problems/0070.爬楼梯完全背包版本.md
+++ b/problems/0070.爬楼梯完全背包版本.md
@@ -88,7 +88,7 @@
以上分析完毕,C++代码如下:
-```
+```c++
class Solution {
public:
int climbStairs(int n) {
From 7ef3bea8998dcacb9b3ca643de0351f137b67b8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98Carl?=
Date: Mon, 4 Oct 2021 09:50:16 +0800
Subject: [PATCH 202/284] =?UTF-8?q?Update=200435.=E6=97=A0=E9=87=8D?=
=?UTF-8?q?=E5=8F=A0=E5=8C=BA=E9=97=B4.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0435.无重叠区间.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0435.无重叠区间.md b/problems/0435.无重叠区间.md
index 830f0c7e..2bf1f4b0 100644
--- a/problems/0435.无重叠区间.md
+++ b/problems/0435.无重叠区间.md
@@ -72,7 +72,7 @@
C++代码如下:
-```c++
+```CPP
class Solution {
public:
// 按照区间右边界排序
From 78efc0ab870f97f015a7babefad86092624889aa Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Mon, 4 Oct 2021 09:55:01 +0800
Subject: [PATCH 203/284] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=200279=20=E5=AE=8C?=
=?UTF-8?q?=E5=85=A8=E5=B9=B3=E6=96=B9=E6=95=B0=20JavaScript=E7=89=88?=
=?UTF-8?q?=E6=9C=AC=E4=BB=A3=E7=A0=81=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
首先 0 不是题目中所说的完全平方数,所有 i 的范围应该从 1 开始;
其次,i <= n 不太合理,增加了大量无用计算,应改成 i**2 (即 i^2)<= n 更为合适
---
problems/0279.完全平方数.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/problems/0279.完全平方数.md b/problems/0279.完全平方数.md
index a00ed47e..b1af7e95 100644
--- a/problems/0279.完全平方数.md
+++ b/problems/0279.完全平方数.md
@@ -334,8 +334,8 @@ var numSquares1 = function(n) {
let dp = new Array(n + 1).fill(Infinity)
dp[0] = 0
- for(let i = 0; i <= n; i++) {
- let val = i * i
+ for(let i = 1; i**2 <= n; i++) {
+ let val = i**2
for(let j = val; j <= n; j++) {
dp[j] = Math.min(dp[j], dp[j - val] + 1)
}
From 7b6fd761297d0d90c80180e8dcce17feff9c3483 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Mon, 4 Oct 2021 18:25:43 +0800
Subject: [PATCH 204/284] =?UTF-8?q?Update=20=E4=BA=8C=E5=8F=89=E6=A0=91?=
=?UTF-8?q?=E4=B8=AD=E9=80=92=E5=BD=92=E5=B8=A6=E7=9D=80=E5=9B=9E=E6=BA=AF?=
=?UTF-8?q?.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
进一步探讨左右子树情况
---
problems/二叉树中递归带着回溯.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/problems/二叉树中递归带着回溯.md b/problems/二叉树中递归带着回溯.md
index 71a3ee5c..0a386fe1 100644
--- a/problems/二叉树中递归带着回溯.md
+++ b/problems/二叉树中递归带着回溯.md
@@ -145,22 +145,22 @@ if (cur->right) {
}
```
-此时就没有回溯了,这个代码就是通过不了的了。
+因为在递归右子树之前需要还原path,所以在左子树递归后必须为了右子树而进行回溯操作。而只右子树自己不添加回溯也可以成功AC。
-如果想把回溯加上,就要 在上面代码的基础上,加上回溯,就可以AC了。
+因此,在上面代码的基础上,再加上左右子树的回溯代码,就可以AC了。
```CPP
if (cur->left) {
path += "->";
traversal(cur->left, path, result); // 左
- path.pop_back(); // 回溯
- path.pop_back();
+ path.pop_back(); // 回溯,抛掉val
+ path.pop_back(); // 回溯,抛掉->
}
if (cur->right) {
path += "->";
traversal(cur->right, path, result); // 右
- path.pop_back(); // 回溯
- path.pop_back();
+ path.pop_back(); // 回溯(非必要)
+ path.pop_back();
}
```
From b4e21799796b4b60fe0a777761aa7d1f1ef94f1b Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Mon, 4 Oct 2021 19:25:58 +0800
Subject: [PATCH 205/284] =?UTF-8?q?Update=200404.=E5=B7=A6=E5=8F=B6?=
=?UTF-8?q?=E5=AD=90=E4=B9=8B=E5=92=8C.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
进一步讨论迭代顺序可能性,实际提交显示前序遍历和后序遍历同样可以AC
---
problems/0404.左叶子之和.md | 37 ++++++++++++++++++++++++++++++++-----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md
index e55981e2..19149285 100644
--- a/problems/0404.左叶子之和.md
+++ b/problems/0404.左叶子之和.md
@@ -42,7 +42,7 @@ if (node->left != NULL && node->left->left == NULL && node->left->right == NULL)
## 递归法
-递归的遍历顺序为后序遍历(左右中),是因为要通过递归函数的返回值来累加求取左叶子数值之和。。
+递归的遍历顺序为后序遍历(左右中),是因为要通过递归函数的返回值来累加求取左叶子数值之和。(前序遍历其实也同样AC)
递归三部曲:
@@ -230,8 +230,8 @@ class Solution {
## Python
-**递归**
-```python
+> 递归后序遍历
+```python3
class Solution:
def sumOfLeftLeaves(self, root: TreeNode) -> int:
if not root:
@@ -246,9 +246,36 @@ class Solution:
return cur_left_leaf_val + left_left_leaves_sum + right_left_leaves_sum
```
+> 递归前序遍历
+```python3
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
+class Solution:
+ def sumOfLeftLeaves(self, root: TreeNode) -> int:
+ # 需要通过中节点来判断其的左节点是否存在;左节点自己的左右节点也是否存在
-**迭代**
-```python
+ if not root: return 0
+
+ # 初始化left_leaf备用
+ left_leaf = 0
+ # 若当前节点的左孩子就是左叶子
+ if root.left and not root.left.left and not root.left.right:
+ left_leaf = root.left.val
+
+ left_left_leaves_sum = self.sumOfLeftLeaves(root.left)
+ right_left_leaves_sum = self.sumOfLeftLeaves(root.right)
+
+
+ return left_leaf + left_left_leaves_sum + right_left_leaves_sum
+```
+
+
+> 迭代
+```python3
class Solution:
def sumOfLeftLeaves(self, root: TreeNode) -> int:
"""
From abd3358314f9580a5a43540c22aa861cb20f0105 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98Carl?=
Date: Tue, 5 Oct 2021 14:21:08 +0800
Subject: [PATCH 206/284] =?UTF-8?q?Update=200206.=E7=BF=BB=E8=BD=AC?=
=?UTF-8?q?=E9=93=BE=E8=A1=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0206.翻转链表.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 0c35f7d7..ec6f3dca 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -100,7 +100,7 @@ public:
具体代码如下(带详细注释):
-```c++
+```CPP
class Solution {
public:
ListNode* reverseList(ListNode* head) {
From 7f051a4dfb160d4aa77e5aaf0768fc05cd7a95aa Mon Sep 17 00:00:00 2001
From: DoubleYellowIce <65336599+DoubleYellowIce@users.noreply.github.com>
Date: Tue, 5 Oct 2021 15:29:06 +0800
Subject: [PATCH 207/284] =?UTF-8?q?Update=200738.=E5=8D=95=E8=B0=83?=
=?UTF-8?q?=E9=80=92=E5=A2=9E=E7=9A=84=E6=95=B0=E5=AD=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
java原先版本中创建了String数组,多次使用Integer.parseInt了方法,这导致不管是耗时还是空间占用都非常高,用时12ms,下面提供一个版本在char数组上原地修改,用时1ms的版本
---
problems/0738.单调递增的数字.md | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/problems/0738.单调递增的数字.md b/problems/0738.单调递增的数字.md
index 0db0db15..61175521 100644
--- a/problems/0738.单调递增的数字.md
+++ b/problems/0738.单调递增的数字.md
@@ -127,6 +127,7 @@ public:
Java:
```java
+版本1
class Solution {
public int monotoneIncreasingDigits(int N) {
String[] strings = (N + "").split("");
@@ -144,6 +145,31 @@ class Solution {
}
}
```
+java版本1中创建了String数组,多次使用Integer.parseInt了方法,这导致不管是耗时还是空间占用都非常高,用时12ms,下面提供一个版本在char数组上原地修改,用时1ms的版本
+```java
+版本2
+class Solution {
+ public int monotoneIncreasingDigits(int n) {
+ if (n==0)return 0;
+ char[] chars= Integer.toString(n).toCharArray();
+ int start=Integer.MAX_VALUE;//start初始值设为最大值,这是为了防止当数字本身是单调递增时,没有一位数字需要改成9的情况
+ for (int i=chars.length-1;i>0;i--){
+ if (chars[i]=start){
+ res.append('9');
+ }else res.append(chars[i]);
+ }
+ return Integer.parseInt(res.toString());
+ }
+}
+```
Python:
From c97ef2dad03d83f1711111d644dafbda3a548602 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Wed, 6 Oct 2021 09:58:52 +0800
Subject: [PATCH 208/284] =?UTF-8?q?=E8=A7=A3=E5=86=B30392=E5=88=A4?=
=?UTF-8?q?=E6=96=AD=E5=AD=90=E5=BA=8F=E5=88=97=20Java=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=97=A0=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0392.判断子序列.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0392.判断子序列.md b/problems/0392.判断子序列.md
index cda0c82d..1a8e55fa 100644
--- a/problems/0392.判断子序列.md
+++ b/problems/0392.判断子序列.md
@@ -141,7 +141,7 @@ public:
Java:
-```
+```java
class Solution {
public boolean isSubsequence(String s, String t) {
int length1 = s.length(); int length2 = t.length();
From 8a35685b3f030672b1cd71d2ad9f357a1d60093a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98Carl?=
Date: Wed, 6 Oct 2021 16:19:22 +0800
Subject: [PATCH 209/284] =?UTF-8?q?Update=200070.=E7=88=AC=E6=A5=BC?=
=?UTF-8?q?=E6=A2=AF=E5=AE=8C=E5=85=A8=E8=83=8C=E5=8C=85=E7=89=88=E6=9C=AC?=
=?UTF-8?q?.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0070.爬楼梯完全背包版本.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0070.爬楼梯完全背包版本.md b/problems/0070.爬楼梯完全背包版本.md
index 3851e7a5..02c995c3 100644
--- a/problems/0070.爬楼梯完全背包版本.md
+++ b/problems/0070.爬楼梯完全背包版本.md
@@ -88,7 +88,7 @@
以上分析完毕,C++代码如下:
-```c++
+```CPP
class Solution {
public:
int climbStairs(int n) {
From 970a441f1034e7c65881c4867d03de300776589f Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Thu, 7 Oct 2021 19:29:26 +0800
Subject: [PATCH 210/284] =?UTF-8?q?Update=200501.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A0=91=E4=B8=AD=E7=9A=84=E4=BC=97=E6=95=B0?=
=?UTF-8?q?.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
规范Python3代码
---
problems/0501.二叉搜索树中的众数.md | 68 ++++++++++++++++++-----------
1 file changed, 42 insertions(+), 26 deletions(-)
diff --git a/problems/0501.二叉搜索树中的众数.md b/problems/0501.二叉搜索树中的众数.md
index 29e5e139..18d9b290 100644
--- a/problems/0501.二叉搜索树中的众数.md
+++ b/problems/0501.二叉搜索树中的众数.md
@@ -470,38 +470,54 @@ class Solution {
## Python
-递归法
+> 递归法
-```python
+```python3
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
+ def __init__(self):
+ self.pre = TreeNode()
+ self.count = 0
+ self.max_count = 0
+ self.result = []
+
def findMode(self, root: TreeNode) -> List[int]:
- if not root: return
- self.pre = root
- self.count = 0 //统计频率
- self.countMax = 0 //最大频率
- self.res = []
- def findNumber(root):
- if not root: return None // 第一个节点
- findNumber(root.left) //左
- if self.pre.val == root.val: //中: 与前一个节点数值相同
- self.count += 1
- else: // 与前一个节点数值不同
- self.pre = root
- self.count = 1
- if self.count > self.countMax: // 如果计数大于最大值频率
- self.countMax = self.count // 更新最大频率
- self.res = [root.val] //更新res
- elif self.count == self.countMax: // 如果和最大值相同,放进res中
- self.res.append(root.val)
- findNumber(root.right) //右
- return
- findNumber(root)
- return self.res
+ if not root: return None
+ self.search_BST(root)
+ return self.result
+
+ def search_BST(self, cur: TreeNode) -> None:
+ if not cur: return None
+ self.search_BST(cur.left)
+ # 第一个节点
+ if not self.pre:
+ self.count = 1
+ # 与前一个节点数值相同
+ elif self.pre.val == cur.val:
+ self.count += 1
+ # 与前一个节点数值不相同
+ else:
+ self.count = 1
+ self.pre = cur
+
+ if self.count == self.max_count:
+ self.result.append(cur.val)
+
+ if self.count > self.max_count:
+ self.max_count = self.count
+ self.result = [cur.val] # 清空self.result,确保result之前的的元素都失效
+
+ self.search_BST(cur.right)
```
-迭代法-中序遍历-不使用额外空间,利用二叉搜索树特性
-```python
+> 迭代法-中序遍历-不使用额外空间,利用二叉搜索树特性
+```python3
class Solution:
def findMode(self, root: TreeNode) -> List[int]:
stack = []
From 42924684ee95003d0f21a80662886f2e88d147ec Mon Sep 17 00:00:00 2001
From: lfeng
Date: Fri, 8 Oct 2021 10:10:48 +0800
Subject: [PATCH 211/284] =?UTF-8?q?Update=200028.=E5=AE=9E=E7=8E=B0strStr.?=
=?UTF-8?q?md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0028.实现strStr.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0028.实现strStr.md b/problems/0028.实现strStr.md
index 2a7b9cfa..1c200a71 100644
--- a/problems/0028.实现strStr.md
+++ b/problems/0028.实现strStr.md
@@ -215,7 +215,7 @@ next数组就可以是前缀表,但是很多实现都是把前缀表统一减
其实**这并不涉及到KMP的原理,而是具体实现,next数组即可以就是前缀表,也可以是前缀表统一减一(右移一位,初始位置为-1)。**
-后面我会提供两种不同的实现代码,大家就明白了了。
+后面我会提供两种不同的实现代码,大家就明白了。
# 使用next数组来匹配
From 9badd38a38a0cccd26cc8c0ef6f0ac732a1c2df5 Mon Sep 17 00:00:00 2001
From: lfeng
Date: Fri, 8 Oct 2021 10:11:31 +0800
Subject: [PATCH 212/284] =?UTF-8?q?Update=200042.=E6=8E=A5=E9=9B=A8?=
=?UTF-8?q?=E6=B0=B4.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0042.接雨水.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index bc397863..25899e38 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -204,7 +204,7 @@ public:
2. 使用单调栈内元素的顺序
-从大到小还是从小打到呢?
+从大到小还是从小到大呢?
从栈头(元素从栈头弹出)到栈底的顺序应该是从小到大的顺序。
From ff7c57a7d00eff78570847e5f8e487c627c8f766 Mon Sep 17 00:00:00 2001
From: lfeng
Date: Fri, 8 Oct 2021 10:12:08 +0800
Subject: [PATCH 213/284] =?UTF-8?q?Update=200225.=E7=94=A8=E9=98=9F?=
=?UTF-8?q?=E5=88=97=E5=AE=9E=E7=8E=B0=E6=A0=88.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0225.用队列实现栈.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0225.用队列实现栈.md b/problems/0225.用队列实现栈.md
index 5adba07f..d9819626 100644
--- a/problems/0225.用队列实现栈.md
+++ b/problems/0225.用队列实现栈.md
@@ -112,7 +112,7 @@ public:
# 优化
-其实这道题目就是用一个队里就够了。
+其实这道题目就是用一个队列就够了。
**一个队列在模拟栈弹出元素的时候只要将队列头部的元素(除了最后一个元素外) 重新添加到队列尾部,此时在去弹出元素就是栈的顺序了。**
From 5e5b3d5f4c926e80e3bad9916f9d13264ff45082 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Fri, 8 Oct 2021 13:12:08 +0800
Subject: [PATCH 214/284] =?UTF-8?q?Update=200404.=E5=B7=A6=E5=8F=B6?=
=?UTF-8?q?=E5=AD=90=E4=B9=8B=E5=92=8C.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
勘误python注释
---
problems/0404.左叶子之和.md | 35 ++++-------------------------------
1 file changed, 4 insertions(+), 31 deletions(-)
diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md
index 19149285..fb574794 100644
--- a/problems/0404.左叶子之和.md
+++ b/problems/0404.左叶子之和.md
@@ -171,10 +171,10 @@ class Solution {
int rightValue = sumOfLeftLeaves(root.right); // 右
int midValue = 0;
- if (root.left != null && root.left.left == null && root.left.right == null) { // 中
+ if (root.left != null && root.left.left == null && root.left.right == null) {
midValue = root.left.val;
}
- int sum = midValue + leftValue + rightValue;
+ int sum = midValue + leftValue + rightValue; // 中
return sum;
}
}
@@ -242,37 +242,10 @@ class Solution:
cur_left_leaf_val = 0
if root.left and not root.left.left and not root.left.right:
- cur_left_leaf_val = root.left.val # 中
+ cur_left_leaf_val = root.left.val
- return cur_left_leaf_val + left_left_leaves_sum + right_left_leaves_sum
+ return cur_left_leaf_val + left_left_leaves_sum + right_left_leaves_sum # 中
```
-> 递归前序遍历
-```python3
-# Definition for a binary tree node.
-# class TreeNode:
-# def __init__(self, val=0, left=None, right=None):
-# self.val = val
-# self.left = left
-# self.right = right
-class Solution:
- def sumOfLeftLeaves(self, root: TreeNode) -> int:
- # 需要通过中节点来判断其的左节点是否存在;左节点自己的左右节点也是否存在
-
- if not root: return 0
-
- # 初始化left_leaf备用
- left_leaf = 0
- # 若当前节点的左孩子就是左叶子
- if root.left and not root.left.left and not root.left.right:
- left_leaf = root.left.val
-
- left_left_leaves_sum = self.sumOfLeftLeaves(root.left)
- right_left_leaves_sum = self.sumOfLeftLeaves(root.right)
-
-
- return left_leaf + left_left_leaves_sum + right_left_leaves_sum
-```
-
> 迭代
```python3
From d131731015f2184cb4ffb428bf414e258225fd61 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Fri, 8 Oct 2021 13:15:58 +0800
Subject: [PATCH 215/284] =?UTF-8?q?Update=200404.=E5=B7=A6=E5=8F=B6?=
=?UTF-8?q?=E5=AD=90=E4=B9=8B=E5=92=8C.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
勘误python注释
---
problems/0404.左叶子之和.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/problems/0404.左叶子之和.md b/problems/0404.左叶子之和.md
index fb574794..ffcd2c8c 100644
--- a/problems/0404.左叶子之和.md
+++ b/problems/0404.左叶子之和.md
@@ -42,7 +42,7 @@ if (node->left != NULL && node->left->left == NULL && node->left->right == NULL)
## 递归法
-递归的遍历顺序为后序遍历(左右中),是因为要通过递归函数的返回值来累加求取左叶子数值之和。(前序遍历其实也同样AC)
+递归的遍历顺序为后序遍历(左右中),是因为要通过递归函数的返回值来累加求取左叶子数值之和。。
递归三部曲:
@@ -230,7 +230,7 @@ class Solution {
## Python
-> 递归后序遍历
+**递归后序遍历**
```python3
class Solution:
def sumOfLeftLeaves(self, root: TreeNode) -> int:
@@ -247,7 +247,7 @@ class Solution:
return cur_left_leaf_val + left_left_leaves_sum + right_left_leaves_sum # 中
```
-> 迭代
+**迭代**
```python3
class Solution:
def sumOfLeftLeaves(self, root: TreeNode) -> int:
From cd1c56ae13b2126d6d0a0f6a09dc5c137aee50d9 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sat, 9 Oct 2021 15:06:36 +0800
Subject: [PATCH 216/284] =?UTF-8?q?Update=200701.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A0=91=E4=B8=AD=E7=9A=84=E6=8F=92=E5=85=A5?=
=?UTF-8?q?=E6=93=8D=E4=BD=9C.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python注释
---
problems/0701.二叉搜索树中的插入操作.md | 35 ++++++++++++++++++-------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/problems/0701.二叉搜索树中的插入操作.md b/problems/0701.二叉搜索树中的插入操作.md
index 0d3d676b..2dca140a 100644
--- a/problems/0701.二叉搜索树中的插入操作.md
+++ b/problems/0701.二叉搜索树中的插入操作.md
@@ -253,21 +253,38 @@ class Solution {
}
}
```
-
+-----
## Python
**递归法** - 有返回值
```python
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
def insertIntoBST(self, root: TreeNode, val: int) -> TreeNode:
- if root is None:
- return TreeNode(val) # 如果当前节点为空,也就意味着val找到了合适的位置,此时创建节点直接返回。
+ # 返回更新后的以当前root为根节点的新树,方便用于更新上一层的父子节点关系链
+
+ # Base Case
+ if not root: return TreeNode(val)
+
+ # 单层递归逻辑:
+ if val < root.val:
+ # 将val插入至当前root的左子树中合适的位置
+ # 并更新当前root的左子树为包含目标val的新左子树
+ root.left = self.insertIntoBST(root.left, val)
+
if root.val < val:
- root.right = self.insertIntoBST(root.right, val) # 递归创建右子树
- if root.val > val:
- root.left = self.insertIntoBST(root.left, val) # 递归创建左子树
- return root
+ # 将val插入至当前root的右子树中合适的位置
+ # 并更新当前root的右子树为包含目标val的新右子树
+ root.right = self.insertIntoBST(root.right, val)
+
+ # 返回更新后的以当前root为根节点的新树
+ return roo
```
**递归法** - 无返回值
@@ -328,7 +345,7 @@ class Solution:
return root
```
-
+-----
## Go
递归法
@@ -374,7 +391,7 @@ func insertIntoBST(root *TreeNode, val int) *TreeNode {
return root
}
```
-
+-----
## JavaScript
有返回值的递归写法
From 9ba63ac729951639b17433f673c447a1d1185255 Mon Sep 17 00:00:00 2001
From: lfeng
Date: Sat, 9 Oct 2021 15:46:44 +0800
Subject: [PATCH 217/284] =?UTF-8?q?Update=200042.=E6=8E=A5=E9=9B=A8?=
=?UTF-8?q?=E6=B0=B4.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0042.接雨水.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index 25899e38..b75865d7 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -143,7 +143,7 @@ public:
当前列雨水面积:min(左边柱子的最高高度,记录右边柱子的最高高度) - 当前柱子高度。
-为了的到两边的最高高度,使用了双指针来遍历,每到一个柱子都向两边遍历一遍,这其实是有重复计算的。我们把每一个位置的左边最高高度记录在一个数组上(maxLeft),右边最高高度记录在一个数组上(maxRight)。这样就避免了重复计算,这就用到了动态规划。
+为了得到两边的最高高度,使用了双指针来遍历,每到一个柱子都向两边遍历一遍,这其实是有重复计算的。我们把每一个位置的左边最高高度记录在一个数组上(maxLeft),右边最高高度记录在一个数组上(maxRight)。这样就避免了重复计算,这就用到了动态规划。
当前位置,左边的最高高度是前一个位置的左边最高高度和本高度的最大值。
From 0d99a3975ee0f99130e8c32059d8b6ef258d9d56 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 10:52:14 +0800
Subject: [PATCH 218/284] =?UTF-8?q?Update=200669.=E4=BF=AE=E5=89=AA?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python注释
---
problems/0669.修剪二叉搜索树.md | 39 +++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/problems/0669.修剪二叉搜索树.md b/problems/0669.修剪二叉搜索树.md
index 23269bb7..09a512c4 100644
--- a/problems/0669.修剪二叉搜索树.md
+++ b/problems/0669.修剪二叉搜索树.md
@@ -264,20 +264,37 @@ class Solution {
```
-## Python
-
+## Python
+**递归**
```python3
-
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
def trimBST(self, root: TreeNode, low: int, high: int) -> TreeNode:
- if not root: return root
- if root.val < low:
- return self.trimBST(root.right,low,high) // 寻找符合区间[low, high]的节点
- if root.val > high:
- return self.trimBST(root.left,low,high) // 寻找符合区间[low, high]的节点
- root.left = self.trimBST(root.left,low,high) // root->left接入符合条件的左孩子
- root.right = self.trimBST(root.right,low,high) // root->right接入符合条件的右孩子
- return root
+ '''
+ 确认递归函数参数以及返回值:返回更新后剪枝后的当前root节点
+ '''
+ # Base Case
+ if not root: return None
+
+ # 单层递归逻辑
+ if root.val < low:
+ # 若当前root节点小于左界:只考虑其右子树,用于替代更新后的其本身,抛弃其左子树整体
+ return self.trimBST(root.right, low, high)
+
+ if high < root.val:
+ # 若当前root节点大于右界:只考虑其左子树,用于替代更新后的其本身,抛弃其右子树整体
+ return self.trimBST(root.left, low, high)
+
+ if low <= root.val <= high:
+ root.left = self.trimBST(root.left, low, high)
+ root.right = self.trimBST(root.right, low, high)
+ # 返回更新后的剪枝过的当前节点root
+ return root
```
## Go
From b314a3f3a53501860e68e861efb119e0567ad53a Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 11:35:48 +0800
Subject: [PATCH 219/284] =?UTF-8?q?Update=200108.=E5=B0=86=E6=9C=89?=
=?UTF-8?q?=E5=BA=8F=E6=95=B0=E7=BB=84=E8=BD=AC=E6=8D=A2=E4=B8=BA=E4=BA=8C?=
=?UTF-8?q?=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python注释
---
problems/0108.将有序数组转换为二叉搜索树.md | 42 +++++++++++++++------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/problems/0108.将有序数组转换为二叉搜索树.md b/problems/0108.将有序数组转换为二叉搜索树.md
index f2bfbb3b..e82d6e95 100644
--- a/problems/0108.将有序数组转换为二叉搜索树.md
+++ b/problems/0108.将有序数组转换为二叉搜索树.md
@@ -304,22 +304,42 @@ class Solution {
}
```
-## Python
+## Python
+**递归**
-递归法:
```python3
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
- def buildaTree(left,right):
- if left > right: return None #左闭右闭的区间,当区间 left > right的时候,就是空节点,当left = right的时候,不为空
- mid = left + (right - left) // 2 #保证数据不会越界
- val = nums[mid]
- root = TreeNode(val)
- root.left = buildaTree(left,mid - 1)
- root.right = buildaTree(mid + 1,right)
- return root
- root = buildaTree(0,len(nums) - 1) #左闭右闭区间
+ '''
+ 构造二叉树:重点是选取数组最中间元素为分割点,左侧是递归左区间;右侧是递归右区间
+ 必然是平衡树
+ 左闭右闭区间
+ '''
+ # 返回根节点
+ root = self.traversal(nums, 0, len(nums)-1)
return root
+
+ def traversal(self, nums: List[int], left: int, right: int) -> TreeNode:
+ # Base Case
+ if left > right:
+ return None
+
+ # 确定左右界的中心,防越界
+ mid = left + (right - left) // 2
+ # 构建根节点
+ mid_root = TreeNode(nums[mid])
+ # 构建以左右界的中心为分割点的左右子树
+ mid_root.left = self.traversal(nums, left, mid-1)
+ mid_root.right = self.traversal(nums, mid+1, right)
+
+ # 返回由被传入的左右界定义的某子树的根节点
+ return mid_root
```
## Go
From b38880b2fdd6f99312811e759a25082be0c48ef0 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 12:26:42 +0800
Subject: [PATCH 220/284] =?UTF-8?q?Update=200538.=E6=8A=8A=E4=BA=8C?=
=?UTF-8?q?=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91=E8=BD=AC=E6=8D=A2=E4=B8=BA?=
=?UTF-8?q?=E7=B4=AF=E5=8A=A0=E6=A0=91.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python注释
---
problems/0538.把二叉搜索树转换为累加树.md | 42 +++++++++++++++++------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/problems/0538.把二叉搜索树转换为累加树.md b/problems/0538.把二叉搜索树转换为累加树.md
index f2b97989..6de98c6f 100644
--- a/problems/0538.把二叉搜索树转换为累加树.md
+++ b/problems/0538.把二叉搜索树转换为累加树.md
@@ -196,20 +196,40 @@ class Solution {
```
## Python
+**递归**
-递归法
-```python
+```python3
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
class Solution:
- def convertBST(self, root: TreeNode) -> TreeNode:
- def buildalist(root):
- if not root: return None
- buildalist(root.right) #右中左遍历
- root.val += self.pre
- self.pre = root.val
- buildalist(root.left)
- self.pre = 0 #记录前一个节点的数值
- buildalist(root)
+ def __init__(self):
+ self.pre = TreeNode()
+
+ def convertBST(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
+ '''
+ 倒序累加替换:
+ [2, 5, 13] -> [[2]+[1]+[0], [2]+[1], [2]] -> [20, 18, 13]
+ '''
+ self.traversal(root)
return root
+
+ def traversal(self, root: TreeNode) -> None:
+ # 因为要遍历整棵树,所以递归函数不需要返回值
+ # Base Case
+ if not root:
+ return None
+ # 单层递归逻辑:中序遍历的反译 - 右中左
+ self.traversal(root.right) # 右
+
+ # 中节点:用当前root的值加上pre的值
+ root.val += self.pre.val # 中
+ self.pre = root
+
+ self.traversal(root.left) # 左
```
## Go
From 9b6cc9a12e7104f76b67ffc11625f0e00e2251cf Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 16:03:11 +0800
Subject: [PATCH 221/284] =?UTF-8?q?Update=200017.=E7=94=B5=E8=AF=9D?=
=?UTF-8?q?=E5=8F=B7=E7=A0=81=E7=9A=84=E5=AD=97=E6=AF=8D=E7=BB=84=E5=90=88?=
=?UTF-8?q?.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python注释规范格式
---
problems/0017.电话号码的字母组合.md | 117 +++++++++++++++-------------
1 file changed, 65 insertions(+), 52 deletions(-)
diff --git a/problems/0017.电话号码的字母组合.md b/problems/0017.电话号码的字母组合.md
index 15a486f2..270398fb 100644
--- a/problems/0017.电话号码的字母组合.md
+++ b/problems/0017.电话号码的字母组合.md
@@ -282,61 +282,74 @@ class Solution {
```
## Python
-
-```Python
+**回溯**
+```python3
class Solution:
- ans = []
- s = ''
- letterMap = {
- '2': 'abc',
- '3': 'def',
- '4': 'ghi',
- '5': 'jkl',
- '6': 'mno',
- '7': 'pqrs',
- '8': 'tuv',
- '9': 'wxyz'
- }
+ def __init__(self):
+ self.answers: List[str] = []
+ self.answer: str = ''
+ self.letter_map = {
+ '2': 'abc',
+ '3': 'def',
+ '4': 'ghi',
+ '5': 'jkl',
+ '6': 'mno',
+ '7': 'pqrs',
+ '8': 'tuv',
+ '9': 'wxyz'
+ }
- def letterCombinations(self, digits):
- self.ans.clear()
- if digits == '':
- return self.ans
- self.backtracking(digits, 0)
- return self.ans
-
- def backtracking(self, digits, index):
- if index == len(digits):
- self.ans.append(self.s)
- return
- else:
- letters = self.letterMap[digits[index]] # 取出数字对应的字符集
- for letter in letters:
- self.s = self.s + letter # 处理
- self.backtracking(digits, index + 1)
- self.s = self.s[:-1] # 回溯
-```
-
-python3:
-
-```py
-class Solution:
def letterCombinations(self, digits: str) -> List[str]:
- res = []
- s = ""
- letterMap = ["","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]
- if not len(digits): return res
- def backtrack(digits,index, s):
- if index == len(digits):
- return res.append(s)
- digit = int(digits[index]) #将index指向的数字转为int
- letters = letterMap[digit] #取数字对应的字符集
- for i in range(len(letters)):
- s += letters[i]
- backtrack(digits, index+1, s) #递归,注意index+1,一下层要处理下一个数字
- s = s[:-1] #回溯
- backtrack(digits, 0, s)
- return res
+ self.answers.clear()
+ if not digits: return []
+ self.backtracking(digits, 0)
+ return self.answers
+
+ def backtracking(self, digits: str, index: int) -> None:
+ # 回溯函数没有返回值
+ # Base Case
+ if index == len(digits): # 当遍历穷尽后的下一层时
+ self.answers.append(self.answer)
+ return
+ # 单层递归逻辑
+ letters: str = self.letter_map[digits[index]]
+ for letter in letters:
+ self.answer += letter # 处理
+ self.backtracking(digits, index + 1) # 递归至下一层
+ self.answer = self.answer[:-1] # 回溯
+```
+**回溯简化**
+```python3
+class Solution:
+ def __init__(self):
+ self.answers: List[str] = []
+ self.letter_map = {
+ '2': 'abc',
+ '3': 'def',
+ '4': 'ghi',
+ '5': 'jkl',
+ '6': 'mno',
+ '7': 'pqrs',
+ '8': 'tuv',
+ '9': 'wxyz'
+ }
+
+ def letterCombinations(self, digits: str) -> List[str]:
+ self.answers.clear()
+ if not digits: return []
+ self.backtracking(digits, 0, '')
+ return self.answers
+
+ def backtracking(self, digits: str, index: int, answer: str) -> None:
+ # 回溯函数没有返回值
+ # Base Case
+ if index == len(digits): # 当遍历穷尽后的下一层时
+ self.answers.append(answer)
+ return
+ # 单层递归逻辑
+ letters: str = self.letter_map[digits[index]]
+ for letter in letters:
+ self.backtracking(digits, index + 1, answer + letter) # 递归至下一层 + 回溯
```
From da254e87ada310eb98a3d400bc2fc109ba3ef6c8 Mon Sep 17 00:00:00 2001
From: Vl_Coding_lover <1773279395@qq.com>
Date: Sun, 10 Oct 2021 16:08:17 +0800
Subject: [PATCH 222/284] =?UTF-8?q?=E6=9B=B4=E6=96=B00121=20=E4=B9=B0?=
=?UTF-8?q?=E8=82=A1=E7=A5=A8=E7=9A=84=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA?=
=?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=E4=BA=86JS=E7=89=88=E6=9C=AC=E7=9A=84?=
=?UTF-8?q?=E8=B4=AA=E5=BF=83=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
第一次向卡哥的LeetCode-Master提交代码 激动.jpg! 对于这道题 第一次接触这道题的时候使用的暴力解一跑直接超时 后来看了题解中使用的贪心算法惊为天人 觉得好有道理!看到这道题里还没有 就加入了一下~希望以后可以为卡哥的项目共享更多代码!
---
problems/0121.买卖股票的最佳时机.md | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/problems/0121.买卖股票的最佳时机.md b/problems/0121.买卖股票的最佳时机.md
index e30fa50a..2f28cf1f 100644
--- a/problems/0121.买卖股票的最佳时机.md
+++ b/problems/0121.买卖股票的最佳时机.md
@@ -335,6 +335,8 @@ func max(a,b int)int {
JavaScript:
+> 动态规划
+
```javascript
const maxProfit = prices => {
const len = prices.length;
@@ -353,7 +355,19 @@ const maxProfit = prices => {
};
```
+> 贪心法
+```javascript
+var maxProfit = function(prices) {
+ let lowerPrice = prices[0];// 重点是维护这个最小值(贪心的思想)
+ let profit = 0;
+ for(let i = 0; i < prices.length; i++){
+ lowerPrice = Math.min(lowerPrice, prices[i]);// 贪心地选择左面的最小价格
+ profit = Math.max(profit, prices[i] - lowerPrice);// 遍历一趟就可以获得最大利润
+ }
+ return profit;
+};
+```
-----------------------
From 1c1b8cb84841780bef64f002a7cbc19dc52b697c Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 16:57:27 +0800
Subject: [PATCH 223/284] =?UTF-8?q?Update=200039.=E7=BB=84=E5=90=88?=
=?UTF-8?q?=E6=80=BB=E5=92=8C.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python代码和注释
---
problems/0039.组合总和.md | 80 +++++++++++++++++++++++++++++++--------
1 file changed, 64 insertions(+), 16 deletions(-)
diff --git a/problems/0039.组合总和.md b/problems/0039.组合总和.md
index e6f65700..4470c79e 100644
--- a/problems/0039.组合总和.md
+++ b/problems/0039.组合总和.md
@@ -264,25 +264,73 @@ class Solution {
}
```
-## Python
+## Python
+**回溯**
```python3
class Solution:
+ def __init__(self):
+ self.path = []
+ self.paths = []
+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
- res = []
- path = []
- def backtrack(candidates,target,sum,startIndex):
- if sum > target: return
- if sum == target: return res.append(path[:])
- for i in range(startIndex,len(candidates)):
- if sum + candidates[i] >target: return #如果 sum + candidates[i] > target 就终止遍历
- sum += candidates[i]
- path.append(candidates[i])
- backtrack(candidates,target,sum,i) #startIndex = i:表示可以重复读取当前的数
- sum -= candidates[i] #回溯
- path.pop() #回溯
- candidates = sorted(candidates) #需要排序
- backtrack(candidates,target,0,0)
- return res
+ '''
+ 因为本题没有组合数量限制,所以只要元素总和大于target就算结束
+ '''
+ self.path.clear()
+ self.paths.clear()
+ self.backtracking(candidates, target, 0, 0)
+ return self.paths
+
+ def backtracking(self, candidates: List[int], target: int, sum_: int, start_index: int) -> None:
+ # Base Case
+ if sum_ == target:
+ self.paths.append(self.path[:]) # 因为是shallow copy,所以不能直接传入self.path
+ return
+ if sum_ > target:
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(candidates)):
+ sum_ += candidates[i]
+ self.path.append(candidates[i])
+ self.backtracking(candidates, target, sum_, i) # 因为无限制重复选取,所以不是i-1
+ sum_ -= candidates[i] # 回溯
+ self.path.pop() # 回溯
+```
+**剪枝回溯**
+```python3
+class Solution:
+ def __init__(self):
+ self.path = []
+ self.paths = []
+
+ def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
+ '''
+ 因为本题没有组合数量限制,所以只要元素总和大于target就算结束
+ '''
+ self.path.clear()
+ self.paths.clear()
+
+ # 为了剪枝需要提前进行排序
+ candidates.sort()
+ self.backtracking(candidates, target, 0, 0)
+ return self.paths
+
+ def backtracking(self, candidates: List[int], target: int, sum_: int, start_index: int) -> None:
+ # Base Case
+ if sum_ == target:
+ self.paths.append(self.path[:]) # 因为是shallow copy,所以不能直接传入self.path
+ return
+ # 单层递归逻辑
+ # 如果本层 sum + condidates[i] > target,就提前结束遍历,剪枝
+ for i in range(start_index, len(candidates)):
+ if sum_ + candidates[i] > target:
+ return
+ sum_ += candidates[i]
+ self.path.append(candidates[i])
+ self.backtracking(candidates, target, sum_, i) # 因为无限制重复选取,所以不是i-1
+ sum_ -= candidates[i] # 回溯
+ self.path.pop() # 回溯
```
## Go
From 92ba20009d5482ecda032ecad87f81d7fa35dc09 Mon Sep 17 00:00:00 2001
From: perfumescent <31856209+perfumescent@users.noreply.github.com>
Date: Sun, 10 Oct 2021 17:55:42 +0800
Subject: [PATCH 224/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A00035=E6=90=9C?=
=?UTF-8?q?=E7=B4=A2=E6=8F=92=E5=85=A5=E4=BD=8D=E7=BD=AE=20golang=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0035.搜索插入位置.md | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md
index 593e3fe5..914c2679 100644
--- a/problems/0035.搜索插入位置.md
+++ b/problems/0035.搜索插入位置.md
@@ -232,7 +232,24 @@ class Solution {
}
}
```
-
+Golang:
+```golang
+// 第一种二分法
+func searchInsert(nums []int, target int) int {
+ l, r := 0, len(nums) - 1
+ for l <= r{
+ m := l + (r - l)/2
+ if nums[m] == target{
+ return m
+ }else if nums[m] > target{
+ r = m - 1
+ }else{
+ l = m + 1
+ }
+ }
+ return r + 1
+}
+```
Python:
```python3
From 637e2f4860cf18a6be046ed5eaaffb3c03de7f88 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 18:08:55 +0800
Subject: [PATCH 225/284] =?UTF-8?q?Update=200040.=E7=BB=84=E5=90=88?=
=?UTF-8?q?=E6=80=BB=E5=92=8CII.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python代码和备注
---
problems/0040.组合总和II.md | 99 +++++++++++++++++++++++++++++++------
1 file changed, 83 insertions(+), 16 deletions(-)
diff --git a/problems/0040.组合总和II.md b/problems/0040.组合总和II.md
index 13e0b35f..bf2685fb 100644
--- a/problems/0040.组合总和II.md
+++ b/problems/0040.组合总和II.md
@@ -296,24 +296,91 @@ class Solution {
```
## Python
-```python
+**回溯+巧妙去重(省去使用used**
+```python3
class Solution:
+ def __init__(self):
+ self.paths = []
+ self.path = []
+
def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
- res = []
- path = []
- def backtrack(candidates,target,sum,startIndex):
- if sum == target: res.append(path[:])
- for i in range(startIndex,len(candidates)): #要对同一树层使用过的元素进行跳过
- if sum + candidates[i] > target: return
- if i > startIndex and candidates[i] == candidates[i-1]: continue #直接用startIndex来去重,要对同一树层使用过的元素进行跳过
- sum += candidates[i]
- path.append(candidates[i])
- backtrack(candidates,target,sum,i+1) #i+1:每个数字在每个组合中只能使用一次
- sum -= candidates[i] #回溯
- path.pop() #回溯
- candidates = sorted(candidates) #首先把给candidates排序,让其相同的元素都挨在一起。
- backtrack(candidates,target,0,0)
- return res
+ '''
+ 类似于求三数之和,求四数之和,为了避免重复组合,需要提前进行数组排序
+ '''
+ self.paths.clear()
+ self.path.clear()
+ # 必须提前进行数组排序,避免重复
+ candidates.sort()
+ self.backtracking(candidates, target, 0, 0)
+ return self.paths
+
+ def backtracking(self, candidates: List[int], target: int, sum_: int, start_index: int) -> None:
+ # Base Case
+ if sum_ == target:
+ self.paths.append(self.path[:])
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(candidates)):
+ # 剪枝,同39.组合总和
+ if sum_ + candidates[i] > target:
+ return
+
+ # 跳过同一树层使用过的元素
+ if i > start_index and candidates[i] == candidates[i-1]:
+ continue
+
+ sum_ += candidates[i]
+ self.path.append(candidates[i])
+ self.backtracking(candidates, target, sum_, i+1)
+ self.path.pop() # 回溯,为了下一轮for loop
+ sum_ -= candidates[i] # 回溯,为了下一轮for loop
+```
+**回溯+去重(使用used)**
+```python3
+class Solution:
+ def __init__(self):
+ self.paths = []
+ self.path = []
+ self.used = []
+
+ def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
+ '''
+ 类似于求三数之和,求四数之和,为了避免重复组合,需要提前进行数组排序
+ 本题需要使用used,用来标记区别同一树层的元素使用重复情况:注意区分递归纵向遍历遇到的重复元素,和for循环遇到的重复元素,这两者的区别
+ '''
+ self.paths.clear()
+ self.path.clear()
+ self.usage_list = [False] * len(candidates)
+ # 必须提前进行数组排序,避免重复
+ candidates.sort()
+ self.backtracking(candidates, target, 0, 0)
+ return self.paths
+
+ def backtracking(self, candidates: List[int], target: int, sum_: int, start_index: int) -> None:
+ # Base Case
+ if sum_ == target:
+ self.paths.append(self.path[:])
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(candidates)):
+ # 剪枝,同39.组合总和
+ if sum_ + candidates[i] > target:
+ return
+
+ # 检查同一树层是否出现曾经使用过的相同元素
+ # 若数组中前后元素值相同,但前者却未被使用(used == False),说明是for loop中的同一树层的相同元素情况
+ if i > 0 and candidates[i] == candidates[i-1] and self.usage_list[i-1] == False:
+ continue
+
+ sum_ += candidates[i]
+ self.path.append(candidates[i])
+ self.usage_list[i] = True
+ self.backtracking(candidates, target, sum_, i+1)
+ self.usage_list[i] = False # 回溯,为了下一轮for loop
+ self.path.pop() # 回溯,为了下一轮for loop
+ sum_ -= candidates[i] # 回溯,为了下一轮for loop
```
## Go:
From ffb43ada5128eeabcf53c8dcfe802513fe3d9624 Mon Sep 17 00:00:00 2001
From: perfumescent <31856209+perfumescent@users.noreply.github.com>
Date: Sun, 10 Oct 2021 18:32:19 +0800
Subject: [PATCH 226/284] =?UTF-8?q?=E5=B0=860034=E7=9A=84=E9=A1=B5?=
=?UTF-8?q?=E9=9D=A2=E9=93=BE=E6=8E=A5=E6=B7=BB=E5=8A=A0=E8=87=B30704?=
=?UTF-8?q?=E7=9A=84=E7=9B=B8=E5=85=B3=E9=A2=98=E7=9B=AE=E6=8E=A8=E8=8D=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0704.二分查找.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0704.二分查找.md b/problems/0704.二分查找.md
index e1900276..1cdc5896 100644
--- a/problems/0704.二分查找.md
+++ b/problems/0704.二分查找.md
@@ -140,7 +140,7 @@ public:
## 相关题目推荐
* [35.搜索插入位置](https://programmercarl.com/0035.搜索插入位置.html)
-* 34.在排序数组中查找元素的第一个和最后一个位置
+* [34.在排序数组中查找元素的第一个和最后一个位置](https://programmercarl.com/0034.%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%92%8C%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E4%BD%8D%E7%BD%AE.html)
* 69.x 的平方根
* 367.有效的完全平方数
From 01af58954329664db03e66f89b3a1156229cf315 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 19:01:54 +0800
Subject: [PATCH 227/284] =?UTF-8?q?Update=200131.=E5=88=86=E5=89=B2?=
=?UTF-8?q?=E5=9B=9E=E6=96=87=E4=B8=B2.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python注释和规范代码
---
problems/0131.分割回文串.md | 162 +++++++++++++++++-------------------
1 file changed, 75 insertions(+), 87 deletions(-)
diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md
index 811044da..3d52146b 100644
--- a/problems/0131.分割回文串.md
+++ b/problems/0131.分割回文串.md
@@ -290,100 +290,88 @@ class Solution {
```
## Python
-```python
-# 版本一
+**回溯+正反序判断回文串**
+```python3
class Solution:
+ def __init__(self):
+ self.paths = []
+ self.path = []
+
def partition(self, s: str) -> List[List[str]]:
- res = []
- path = [] #放已经回文的子串
- def backtrack(s,startIndex):
- if startIndex >= len(s): #如果起始位置已经大于s的大小,说明已经找到了一组分割方案了
- return res.append(path[:])
- for i in range(startIndex,len(s)):
- p = s[startIndex:i+1] #获取[startIndex,i+1]在s中的子串
- if p == p[::-1]: path.append(p) #是回文子串
- else: continue #不是回文,跳过
- backtrack(s,i+1) #寻找i+1为起始位置的子串
- path.pop() #回溯过程,弹出本次已经填在path的子串
- backtrack(s,0)
- return res
-
+ '''
+ 递归用于纵向遍历
+ for循环用于横向遍历
+ 当切割线迭代至字符串末尾,说明找到一种方法
+ 类似组合问题,为了不重复切割同一位置,需要start_index来做标记下一轮递归的起始位置(切割线)
+ '''
+ self.path.clear()
+ self.paths.clear()
+ self.backtracking(s, 0)
+ return self.paths
+
+ def backtracking(self, s: str, start_index: int) -> None:
+ # Base Case
+ if start_index >= len(s):
+ self.paths.append(self.path[:])
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(s)):
+ # 此次比其他组合题目多了一步判断:
+ # 判断被截取的这一段子串([start_index, i])是否为回文串
+ temp = s[start_index:i+1]
+ if temp == temp[::-1]: # 若反序和正序相同,意味着这是回文串
+ self.path.append(temp)
+ self.backtracking(s, i+1) # 递归纵向遍历:从下一处进行切割,判断其余是否仍为回文串
+ self.path.pop()
+ else:
+ continue
```
-```python
-# 版本二
+**回溯+函数判断回文串**
+```python3
class Solution:
+ def __init__(self):
+ self.paths = []
+ self.path = []
+
def partition(self, s: str) -> List[List[str]]:
- res = []
- path = [] #放已经回文的子串
- # 双指针法判断是否是回文串
- def isPalindrome(s):
- n = len(s)
- i, j = 0, n - 1
- while i < j:
- if s[i] != s[j]:return False
- i += 1
- j -= 1
- return True
-
- def backtrack(s, startIndex):
- if startIndex >= len(s): # 如果起始位置已经大于s的大小,说明已经找到了一组分割方案了
- res.append(path[:])
- return
- for i in range(startIndex, len(s)):
- p = s[startIndex:i+1] # 获取[startIndex,i+1]在s中的子串
- if isPalindrome(p): # 是回文子串
- path.append(p)
- else: continue #不是回文,跳过
- backtrack(s, i + 1)
- path.pop() #回溯过程,弹出本次已经填在path的子串
- backtrack(s, 0)
- return res
-```
-## Go
+ '''
+ 递归用于纵向遍历
+ for循环用于横向遍历
+ 当切割线迭代至字符串末尾,说明找到一种方法
+ 类似组合问题,为了不重复切割同一位置,需要start_index来做标记下一轮递归的起始位置(切割线)
+ '''
+ self.path.clear()
+ self.paths.clear()
+ self.backtracking(s, 0)
+ return self.paths
-注意切片(go切片是披着值类型外衣的引用类型)
+ def backtracking(self, s: str, start_index: int) -> None:
+ # Base Case
+ if start_index >= len(s):
+ self.paths.append(self.path[:])
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(s)):
+ # 此次比其他组合题目多了一步判断:
+ # 判断被截取的这一段子串([start_index, i])是否为回文串
+ if self.is_palindrome(s, start_index, i):
+ self.path.append(s[start_index:i+1])
+ self.backtracking(s, i+1) # 递归纵向遍历:从下一处进行切割,判断其余是否仍为回文串
+ self.path.pop() # 回溯
+ else:
+ continue
-```go
-func partition(s string) [][]string {
- var tmpString []string//切割字符串集合
- var res [][]string//结果集合
- backTracking(s,tmpString,0,&res)
- return res
-}
-func backTracking(s string,tmpString []string,startIndex int,res *[][]string){
- if startIndex==len(s){//到达字符串末尾了
- //进行一次切片拷贝,怕之后的操作影响tmpString切片内的值
- t := make([]string, len(tmpString))
- copy(t, tmpString)
- *res=append(*res,t)
- }
- for i:=startIndex;i bool:
+ i: int = start
+ j: int = end
+ while i < j:
+ if s[i] != s[j]:
+ return False
+ i += 1
+ j -= 1
+ return True
```
## javaScript
From d2667d3eda08c0739814caba0cb28a4afdc6128a Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Sun, 10 Oct 2021 19:05:53 +0800
Subject: [PATCH 228/284] =?UTF-8?q?Update=200131.=E5=88=86=E5=89=B2?=
=?UTF-8?q?=E5=9B=9E=E6=96=87=E4=B8=B2.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充go代码
---
problems/0131.分割回文串.md | 45 +++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md
index 3d52146b..2070b8c3 100644
--- a/problems/0131.分割回文串.md
+++ b/problems/0131.分割回文串.md
@@ -374,6 +374,51 @@ class Solution:
return True
```
+## Go
+**注意切片(go切片是披着值类型外衣的引用类型)**
+```go
+func partition(s string) [][]string {
+ var tmpString []string//切割字符串集合
+ var res [][]string//结果集合
+ backTracking(s,tmpString,0,&res)
+ return res
+}
+func backTracking(s string,tmpString []string,startIndex int,res *[][]string){
+ if startIndex==len(s){//到达字符串末尾了
+ //进行一次切片拷贝,怕之后的操作影响tmpString切片内的值
+ t := make([]string, len(tmpString))
+ copy(t, tmpString)
+ *res=append(*res,t)
+ }
+ for i:=startIndex;i
Date: Mon, 11 Oct 2021 13:30:42 +0800
Subject: [PATCH 229/284] =?UTF-8?q?Update=200093.=E5=A4=8D=E5=8E=9FIP?=
=?UTF-8?q?=E5=9C=B0=E5=9D=80.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
python3代码修正和补充注释
---
problems/0093.复原IP地址.md | 65 +++++++++++++++++++++++--------------
1 file changed, 40 insertions(+), 25 deletions(-)
diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md
index 4e56ddc4..1d8ad296 100644
--- a/problems/0093.复原IP地址.md
+++ b/problems/0093.复原IP地址.md
@@ -342,32 +342,47 @@ class Solution:
```
python3:
-```python
-class Solution(object):
- def restoreIpAddresses(self, s):
- """
- :type s: str
- :rtype: List[str]
- """
- ans = []
- path = []
- def backtrack(path, startIndex):
- if len(path) == 4:
- if startIndex == len(s):
- ans.append(".".join(path[:]))
- return
- for i in range(startIndex+1, min(startIndex+4, len(s)+1)): # 剪枝
- string = s[startIndex:i]
- if not 0 <= int(string) <= 255:
- continue
- if not string == "0" and not string.lstrip('0') == string:
- continue
- path.append(string)
- backtrack(path, i)
- path.pop()
+```python3
+class Solution:
+ def __init__(self):
+ self.result = []
- backtrack([], 0)
- return ans```
+ def restoreIpAddresses(self, s: str) -> List[str]:
+ '''
+ 本质切割问题使用回溯搜索法,本题只能切割三次,所以纵向递归总共四层
+ 因为不能重复分割,所以需要start_index来记录下一层递归分割的起始位置
+ 添加变量point_num来记录逗号的数量[0,3]
+ '''
+ self.result.clear()
+ if len(s) > 12: return []
+ self.backtracking(s, 0, 0)
+ return self.result
+
+ def backtracking(self, s: str, start_index: int, point_num: int) -> None:
+ # Base Case
+ if point_num == 3:
+ if self.is_valid(s, start_index, len(s)-1):
+ self.result.append(s[:])
+ return
+ # 单层递归逻辑
+ for i in range(start_index, len(s)):
+ # [start_index, i]就是被截取的子串
+ if self.is_valid(s, start_index, i):
+ s = s[:i+1] + '.' + s[i+1:]
+ self.backtracking(s, i+2, point_num+1) # 在填入.后,下一子串起始后移2位
+ s = s[:i+1] + s[i+2:] # 回溯
+ else:
+ # 若当前被截取的子串大于255或者大于三位数,直接结束本层循环
+ break
+
+ def is_valid(self, s: str, start: int, end: int) -> bool:
+ if start > end: return False
+ # 若数字是0开头,不合法
+ if s[start] == '0' and start != end:
+ return False
+ if not 0 <= int(s[start:end+1]) <= 255:
+ return False
+ return True
```
From cf7d7a7399127055e627a4b519b428aaa6a67784 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Mon, 11 Oct 2021 14:00:02 +0800
Subject: [PATCH 230/284] =?UTF-8?q?Update=200078.=E5=AD=90=E9=9B=86.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充注释和调整python格式
---
problems/0078.子集.md | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/problems/0078.子集.md b/problems/0078.子集.md
index 878133a1..1ffc51ea 100644
--- a/problems/0078.子集.md
+++ b/problems/0078.子集.md
@@ -207,17 +207,28 @@ class Solution {
## Python
```python3
class Solution:
+ def __init__(self):
+ self.path: List[int] = []
+ self.paths: List[List[int]] = []
+
def subsets(self, nums: List[int]) -> List[List[int]]:
- res = []
- path = []
- def backtrack(nums,startIndex):
- res.append(path[:]) #收集子集,要放在终止添加的上面,否则会漏掉自己
- for i in range(startIndex,len(nums)): #当startIndex已经大于数组的长度了,就终止了,for循环本来也结束了,所以不需要终止条件
- path.append(nums[i])
- backtrack(nums,i+1) #递归
- path.pop() #回溯
- backtrack(nums,0)
- return res
+ self.paths.clear()
+ self.path.clear()
+ self.backtracking(nums, 0)
+ return self.paths
+
+ def backtracking(self, nums: List[int], start_index: int) -> None:
+ # 收集子集,要先于终止判断
+ self.paths.append(self.path[:])
+ # Base Case
+ if start_index == len(nums):
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(nums)):
+ self.path.append(nums[i])
+ self.backtracking(nums, i+1)
+ self.path.pop() # 回溯
```
## Go
From ecb99c2a296ba503c4d71e59a256b8de0c77db58 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Mon, 11 Oct 2021 14:44:00 +0800
Subject: [PATCH 231/284] =?UTF-8?q?Update=200090.=E5=AD=90=E9=9B=86II.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修正python代码补充注释
---
problems/0090.子集II.md | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/problems/0090.子集II.md b/problems/0090.子集II.md
index 7ae7c6c2..665137e9 100644
--- a/problems/0090.子集II.md
+++ b/problems/0090.子集II.md
@@ -207,20 +207,30 @@ class Solution {
Python:
```python3
class Solution:
+ def __init__(self):
+ self.paths = []
+ self.path = []
+
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
- res = [] #存放符合条件结果的集合
- path = [] #用来存放符合条件结果
- def backtrack(nums,startIndex):
- res.append(path[:])
- for i in range(startIndex,len(nums)):
- if i > startIndex and nums[i] == nums[i - 1]: #我们要对同一树层使用过的元素进行跳过
- continue
- path.append(nums[i])
- backtrack(nums,i+1) #递归
- path.pop() #回溯
- nums = sorted(nums) #去重需要排序
- backtrack(nums,0)
- return res
+ nums.sort()
+ self.backtracking(nums, 0)
+ return self.paths
+
+ def backtracking(self, nums: List[int], start_index: int) -> None:
+ # ps.空集合仍符合要求
+ self.paths.append(self.path[:])
+ # Base Case
+ if start_index == len(nums):
+ return
+
+ # 单层递归逻辑
+ for i in range(start_index, len(nums)):
+ if i > start_index and nums[i] == nums[i-1]:
+ # 当前后元素值相同时,跳入下一个循环,去重
+ continue
+ self.path.append(nums[i])
+ self.backtracking(nums, i+1)
+ self.path.pop()
```
Go:
From 07dd85094c722fa71fb4460781b10a49ebe11efb Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Mon, 11 Oct 2021 16:10:34 +0800
Subject: [PATCH 232/284] =?UTF-8?q?Update=200491.=E9=80=92=E5=A2=9E?=
=?UTF-8?q?=E5=AD=90=E5=BA=8F=E5=88=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补全python代码补充注释
---
problems/0491.递增子序列.md | 93 ++++++++++++++++++++++++++++---------
1 file changed, 71 insertions(+), 22 deletions(-)
diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md
index e947b2b9..e8ab8eca 100644
--- a/problems/0491.递增子序列.md
+++ b/problems/0491.递增子序列.md
@@ -229,32 +229,81 @@ class Solution {
}
}
```
-
-
Python:
+**回溯**
```python3
class Solution:
- def findSubsequences(self, nums: List[int]) -> List[List[int]]:
- res = []
- path = []
- def backtrack(nums,startIndex):
- repeat = [] #这里使用数组来进行去重操作
- if len(path) >=2:
- res.append(path[:]) #注意这里不要加return,要取树上的节点
- for i in range(startIndex,len(nums)):
- if nums[i] in repeat:
- continue
- if len(path) >= 1:
- if nums[i] < path[-1]:
- continue
- repeat.append(nums[i]) #记录这个元素在本层用过了,本层后面不能再用了
- path.append(nums[i])
- backtrack(nums,i+1)
- path.pop()
- backtrack(nums,0)
- return res
-```
+ def __init__(self):
+ self.paths = []
+ self.path = []
+ def findSubsequences(self, nums: List[int]) -> List[List[int]]:
+ '''
+ 本题求自增子序列,所以不能改变原数组顺序
+ '''
+ self.backtracking(nums, 0)
+ return self.paths
+
+ def backtracking(self, nums: List[int], start_index: int):
+ # 收集结果,同78.子集,仍要置于终止条件之前
+ if len(self.path) >= 2:
+ # 本题要求所有的节点
+ self.paths.append(self.path[:])
+
+ # Base Case(可忽略)
+ if start_index == len(nums):
+ return
+
+ # 单层递归逻辑
+ # 深度遍历中每一层都会有一个全新的usage_list用于记录本层元素是否重复使用
+ usage_list = set()
+ # 同层横向遍历
+ for i in range(start_index, len(nums)):
+ # 若当前元素值小于前一个时(非递增)或者曾用过,跳入下一循环
+ if (self.path and nums[i] < self.path[-1]) or nums[i] in usage_list:
+ continue
+ usage_list.add(nums[i])
+ self.path.append(nums[i])
+ self.backtracking(nums, i+1)
+ self.path.pop()
+```
+**回溯+哈希表去重**
+```python3
+class Solution:
+ def __init__(self):
+ self.paths = []
+ self.path = []
+
+ def findSubsequences(self, nums: List[int]) -> List[List[int]]:
+ '''
+ 本题求自增子序列,所以不能改变原数组顺序
+ '''
+ self.backtracking(nums, 0)
+ return self.paths
+
+ def backtracking(self, nums: List[int], start_index: int):
+ # 收集结果,同78.子集,仍要置于终止条件之前
+ if len(self.path) >= 2:
+ # 本题要求所有的节点
+ self.paths.append(self.path[:])
+
+ # Base Case(可忽略)
+ if start_index == len(nums):
+ return
+
+ # 单层递归逻辑
+ # 深度遍历中每一层都会有一个全新的usage_list用于记录本层元素是否重复使用
+ usage_list = [False] * 201 # 使用列表去重,题中取值范围[-100, 100]
+ # 同层横向遍历
+ for i in range(start_index, len(nums)):
+ # 若当前元素值小于前一个时(非递增)或者曾用过,跳入下一循环
+ if (self.path and nums[i] < self.path[-1]) or usage_list[nums[i]+100] == True:
+ continue
+ usage_list[nums[i]+100] = True
+ self.path.append(nums[i])
+ self.backtracking(nums, i+1)
+ self.path.pop()
+```
Go:
```golang
From 68502287a2281abc90a5ee8bff621556ed5aea94 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Mon, 11 Oct 2021 16:41:27 +0800
Subject: [PATCH 233/284] =?UTF-8?q?Update=200046.=E5=85=A8=E6=8E=92?=
=?UTF-8?q?=E5=88=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化python代码以及补充注释
---
problems/0046.全排列.md | 88 ++++++++++++++++++++++++++---------------
1 file changed, 56 insertions(+), 32 deletions(-)
diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md
index 1e1252ae..5e36927c 100644
--- a/problems/0046.全排列.md
+++ b/problems/0046.全排列.md
@@ -211,44 +211,68 @@ class Solution {
```
Python:
+**回溯**
```python3
class Solution:
- def permute(self, nums: List[int]) -> List[List[int]]:
- res = [] #存放符合条件结果的集合
- path = [] #用来存放符合条件的结果
- used = [] #用来存放已经用过的数字
- def backtrack(nums,used):
- if len(path) == len(nums):
- return res.append(path[:]) #此时说明找到了一组
- for i in range(0,len(nums)):
- if nums[i] in used:
- continue #used里已经收录的元素,直接跳过
- path.append(nums[i])
- used.append(nums[i])
- backtrack(nums,used)
- used.pop()
- path.pop()
- backtrack(nums,used)
- return res
-```
+ def __init__(self):
+ self.path = []
+ self.paths = []
-Python(优化,不用used数组):
+ def permute(self, nums: List[int]) -> List[List[int]]:
+ '''
+ 因为本题排列是有序的,这意味着同一层的元素可以重复使用,但同一树枝上不能重复使用(usage_list)
+ 所以处理排列问题每层都需要从头搜索,故不再使用start_index
+ '''
+ usage_list = [False] * len(nums)
+ self.backtracking(nums, usage_list)
+ return self.paths
+
+ def backtracking(self, nums: List[int], usage_list: List[bool]) -> None:
+ # Base Case本题求叶子节点
+ if len(self.path) == len(nums):
+ self.paths.append(self.path[:])
+ return
+
+ # 单层递归逻辑
+ for i in range(0, len(nums)): # 从头开始搜索
+ # 若遇到self.path里已收录的元素,跳过
+ if usage_list[i] == True:
+ continue
+ usage_list[i] = True
+ self.path.append(nums[i])
+ self.backtracking(nums, usage_list) # 纵向传递使用信息,去重
+ self.path.pop()
+ usage_list[i] = False
+```
+**回溯+丢掉usage_list**
```python3
class Solution:
+ def __init__(self):
+ self.path = []
+ self.paths = []
+
def permute(self, nums: List[int]) -> List[List[int]]:
- res = [] #存放符合条件结果的集合
- path = [] #用来存放符合条件的结果
- def backtrack(nums):
- if len(path) == len(nums):
- return res.append(path[:]) #此时说明找到了一组
- for i in range(0,len(nums)):
- if nums[i] in path: #path里已经收录的元素,直接跳过
- continue
- path.append(nums[i])
- backtrack(nums) #递归
- path.pop() #回溯
- backtrack(nums)
- return res
+ '''
+ 因为本题排列是有序的,这意味着同一层的元素可以重复使用,但同一树枝上不能重复使用
+ 所以处理排列问题每层都需要从头搜索,故不再使用start_index
+ '''
+ self.backtracking(nums)
+ return self.paths
+
+ def backtracking(self, nums: List[int]) -> None:
+ # Base Case本题求叶子节点
+ if len(self.path) == len(nums):
+ self.paths.append(self.path[:])
+ return
+
+ # 单层递归逻辑
+ for i in range(0, len(nums)): # 从头开始搜索
+ # 若遇到self.path里已收录的元素,跳过
+ if nums[i] in self.path:
+ continue
+ self.path.append(nums[i])
+ self.backtracking(nums)
+ self.path.pop()
```
Go:
From 536b3594226cc989e624cae8b2603673f3199176 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8D=89=E8=8E=93=E5=B0=8F=E9=A5=BC=E8=82=9D?=
Date: Mon, 11 Oct 2021 18:56:47 +0800
Subject: [PATCH 234/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200042=E6=8E=A5?=
=?UTF-8?q?=E9=9B=A8=E6=B0=B4=20Go=E8=AF=AD=E8=A8=80=20=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0042.接雨水.md | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/problems/0042.接雨水.md b/problems/0042.接雨水.md
index b75865d7..9b26bc6b 100644
--- a/problems/0042.接雨水.md
+++ b/problems/0042.接雨水.md
@@ -579,6 +579,31 @@ class Solution:
Go:
+```go
+func trap(height []int) int {
+ var left, right, leftMax, rightMax, res int
+ right = len(height) - 1
+ for left < right {
+ if height[left] < height[right] {
+ if height[left] >= leftMax {
+ leftMax = height[left] // 设置左边最高柱子
+ } else {
+ res += leftMax - height[left] // //右边必定有柱子挡水,所以遇到所有值小于等于leftMax的,全部加入水池中
+ }
+ left++
+ } else {
+ if height[right] > rightMax {
+ rightMax = height[right] // //设置右边最高柱子
+ } else {
+ res += rightMax - height[right] // //左边必定有柱子挡水,所以,遇到所有值小于等于rightMax的,全部加入水池
+ }
+ right--
+ }
+ }
+ return res
+}
+```
+
JavaScript:
```javascript
//双指针
From 6287b670aada181cd398782c9a681a96f3874a56 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Tue, 12 Oct 2021 14:11:05 +0800
Subject: [PATCH 235/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=201365=20=E6=9C=89?=
=?UTF-8?q?=E5=A4=9A=E5=B0=91=E4=B8=AA=E5=B0=8F=E4=BA=8E=E5=BD=93=E5=89=8D?=
=?UTF-8?q?=E6=95=B0=E5=AD=97=E7=9A=84=E6=95=B0=E5=AD=97=20JavaScript?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=8D=E4=BD=BF=E7=94=A8=E5=93=88=E5=B8=8C?=
=?UTF-8?q?=E8=A1=A8=E7=9A=84=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1365.有多少小于当前数字的数字.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/problems/1365.有多少小于当前数字的数字.md b/problems/1365.有多少小于当前数字的数字.md
index 69654930..9f282209 100644
--- a/problems/1365.有多少小于当前数字的数字.md
+++ b/problems/1365.有多少小于当前数字的数字.md
@@ -156,6 +156,7 @@ Go:
JavaScript:
```javascript
+// 方法一:使用哈希表记录位置
var smallerNumbersThanCurrent = function(nums) {
const map = new Map();// 记录数字 nums[i] 有多少个比它小的数字
const res = nums.slice(0);//深拷贝nums
@@ -171,9 +172,27 @@ var smallerNumbersThanCurrent = function(nums) {
}
return res;
};
+
+// 方法二:不使用哈希表,只使用一个额外数组
+/**
+ * @param {number[]} nums
+ * @return {number[]}
+ */
+var smallerNumbersThanCurrent = function(nums) {
+ let array = [...nums]; // 深拷贝
+ // 升序排列,此时数组元素下标即是比他小的元素的个数
+ array = array.sort((a, b) => a-b);
+ let res = [];
+ nums.forEach( x => {
+ // 即使元素重复也不怕,indexOf 只返回找到的第一个元素的下标
+ res.push(array.indexOf(x));
+ })
+ return res;
+};
```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From dd4515a68b4e4f32b473b72c475ee7099520fd31 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Tue, 12 Oct 2021 14:50:44 +0800
Subject: [PATCH 236/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=201207=20=E7=8B=AC?=
=?UTF-8?q?=E4=B8=80=E6=97=A0=E4=BA=8C=E7=9A=84=E5=87=BA=E7=8E=B0=E6=AC=A1?=
=?UTF-8?q?=E6=95=B0=20JavaScript=E7=89=88=E6=9C=AC=20=E4=BD=BF=E7=94=A8?=
=?UTF-8?q?=E5=93=88=E5=B8=8C=E8=A1=A8=E5=92=8C=E9=9B=86=E5=90=88=E7=9A=84?=
=?UTF-8?q?=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/1207.独一无二的出现次数.md | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/problems/1207.独一无二的出现次数.md b/problems/1207.独一无二的出现次数.md
index a65b26e6..808ff9f8 100644
--- a/problems/1207.独一无二的出现次数.md
+++ b/problems/1207.独一无二的出现次数.md
@@ -119,6 +119,7 @@ Go:
JavaScript:
``` javascript
+// 方法一:使用数组记录元素出现次数
var uniqueOccurrences = function(arr) {
const count = new Array(2002).fill(0);// -1000 <= arr[i] <= 1000
for(let i = 0; i < arr.length; i++){
@@ -134,6 +135,21 @@ var uniqueOccurrences = function(arr) {
}
return true;
};
+
+// 方法二:使用Map 和 Set
+/**
+ * @param {number[]} arr
+ * @return {boolean}
+ */
+var uniqueOccurrences = function(arr) {
+ // 记录每个元素出现次数
+ let map = new Map();
+ arr.forEach( x => {
+ map.set(x, (map.get(x) || 0) + 1);
+ })
+ // Set() 里的元素是不重复的。如果有元素出现次数相同,则最后的set的长度不等于map的长度
+ return map.size === new Set(map.values()).size
+};
```
-----------------------
From f70dc0595ae3ce0c88eab9718dd25c1153b426f0 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Tue, 12 Oct 2021 14:54:53 +0800
Subject: [PATCH 237/284] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=AE=97=E6=B3=95?=
=?UTF-8?q?=E6=A8=A1=E6=9D=BFC++=E4=BB=A3=E7=A0=81=E6=B2=A1=E6=9C=89?=
=?UTF-8?q?=E6=A0=B7=E5=BC=8F=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/算法模板.md | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/problems/算法模板.md b/problems/算法模板.md
index df823e81..c772c178 100644
--- a/problems/算法模板.md
+++ b/problems/算法模板.md
@@ -8,7 +8,7 @@
## 二分查找法
-```
+```c++
class Solution {
public:
int searchInsert(vector& nums, int target) {
@@ -33,7 +33,7 @@ public:
## KMP
-```
+```c++
void kmp(int* next, const string& s){
next[0] = -1;
int j = -1;
@@ -53,7 +53,7 @@ void kmp(int* next, const string& s){
二叉树的定义:
-```
+```c++
struct TreeNode {
int val;
TreeNode *left;
@@ -65,7 +65,7 @@ struct TreeNode {
### 深度优先遍历(递归)
前序遍历(中左右)
-```
+```c++
void traversal(TreeNode* cur, vector& vec) {
if (cur == NULL) return;
vec.push_back(cur->val); // 中 ,同时也是处理节点逻辑的地方
@@ -74,7 +74,7 @@ void traversal(TreeNode* cur, vector& vec) {
}
```
中序遍历(左中右)
-```
+```c++
void traversal(TreeNode* cur, vector& vec) {
if (cur == NULL) return;
traversal(cur->left, vec); // 左
@@ -83,7 +83,7 @@ void traversal(TreeNode* cur, vector& vec) {
}
```
后序遍历(左右中)
-```
+```c++
void traversal(TreeNode* cur, vector& vec) {
if (cur == NULL) return;
traversal(cur->left, vec); // 左
@@ -97,7 +97,7 @@ void traversal(TreeNode* cur, vector& vec) {
相关题解:[0094.二叉树的中序遍历](https://github.com/youngyangyang04/leetcode/blob/master/problems/0094.二叉树的中序遍历.md)
前序遍历(中左右)
-```
+```c++
vector preorderTraversal(TreeNode* root) {
vector result;
stack st;
@@ -123,7 +123,7 @@ vector preorderTraversal(TreeNode* root) {
```
中序遍历(左中右)
-```
+```c++
vector inorderTraversal(TreeNode* root) {
vector result; // 存放中序遍历的元素
stack st;
@@ -148,7 +148,7 @@ vector inorderTraversal(TreeNode* root) {
```
后序遍历(左右中)
-```
+```c++
vector postorderTraversal(TreeNode* root) {
vector result;
stack st;
@@ -176,7 +176,7 @@ vector postorderTraversal(TreeNode* root) {
相关题解:[0102.二叉树的层序遍历](https://programmercarl.com/0102.二叉树的层序遍历.html)
-```
+```c++
vector> levelOrder(TreeNode* root) {
queue que;
if (root != NULL) que.push(root);
@@ -212,7 +212,7 @@ vector> levelOrder(TreeNode* root) {
### 二叉树深度
-```
+```c++
int getDepth(TreeNode* node) {
if (node == NULL) return 0;
return 1 + max(getDepth(node->left), getDepth(node->right));
@@ -221,7 +221,7 @@ int getDepth(TreeNode* node) {
### 二叉树节点数量
-```
+```c++
int countNodes(TreeNode* root) {
if (root == NULL) return 0;
return 1 + countNodes(root->left) + countNodes(root->right);
@@ -229,7 +229,7 @@ int countNodes(TreeNode* root) {
```
## 回溯算法
-```
+```c++
void backtracking(参数) {
if (终止条件) {
存放结果;
@@ -247,7 +247,7 @@ void backtracking(参数) {
## 并查集
-```
+```c++
int n = 1005; // 更具题意而定
int father[1005];
From e2686eb2af462585fac0cfab898de14b0cf337a1 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Tue, 12 Oct 2021 20:49:36 +0800
Subject: [PATCH 238/284] =?UTF-8?q?Update=200037.=E8=A7=A3=E6=95=B0?=
=?UTF-8?q?=E7=8B=AC.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
规范python代码补充注释
---
problems/0037.解数独.md | 109 ++++++++++++----------------------------
1 file changed, 32 insertions(+), 77 deletions(-)
diff --git a/problems/0037.解数独.md b/problems/0037.解数独.md
index 7bc07252..d5b450aa 100644
--- a/problems/0037.解数独.md
+++ b/problems/0037.解数独.md
@@ -293,85 +293,40 @@ class Solution:
"""
Do not return anything, modify board in-place instead.
"""
- def backtrack(board):
- for i in range(len(board)): #遍历行
- for j in range(len(board[0])): #遍历列
- if board[i][j] != ".": continue
- for k in range(1,10): #(i, j) 这个位置放k是否合适
- if isValid(i,j,k,board):
- board[i][j] = str(k) #放置k
- if backtrack(board): return True #如果找到合适一组立刻返回
- board[i][j] = "." #回溯,撤销k
- return False #9个数都试完了,都不行,那么就返回false
- return True #遍历完没有返回false,说明找到了合适棋盘位置了
- def isValid(row,col,val,board):
- for i in range(9): #判断行里是否重复
- if board[row][i] == str(val):
+ self.backtracking(board)
+
+ def backtracking(self, board: List[List[str]]) -> bool:
+ # 若有解,返回True;若无解,返回False
+ for i in range(len(board)): # 遍历行
+ for j in range(len(board[0])): # 遍历列
+ # 若空格内已有数字,跳过
+ if board[i][j] != '.': continue
+ for k in range(1, 10):
+ if self.is_valid(i, j, k, board):
+ board[i][j] = str(k)
+ if self.backtracking(board): return True
+ board[i][j] = '.'
+ # 若数字1-9都不能成功填入空格,返回False无解
+ return False
+ return True # 有解
+
+ def is_valid(self, row: int, col: int, val: int, board: List[List[str]]) -> bool:
+ # 判断同一行是否冲突
+ for i in range(9):
+ if board[row][i] == str(val):
+ return False
+ # 判断同一列是否冲突
+ for j in range(9):
+ if board[j][col] == str(val):
+ return False
+ # 判断同一九宫格是否有冲突
+ start_row = (row // 3) * 3
+ start_col = (col // 3) * 3
+ for i in range(start_row, start_row + 3):
+ for j in range(start_col, start_col + 3):
+ if board[i][j] == str(val):
return False
- for j in range(9): #判断列里是否重复
- if board[j][col] == str(val):
- return False
- startRow = (row // 3) * 3
- startcol = (col // 3) * 3
- for i in range(startRow,startRow + 3): #判断9方格里是否重复
- for j in range(startcol,startcol + 3):
- if board[i][j] == str(val):
- return False
- return True
- backtrack(board)
-```
-
-Python3:
-
-```python3
-class Solution:
- def __init__(self) -> None:
- self.board = []
-
- def isValid(self, row: int, col: int, target: int) -> bool:
- for idx in range(len(self.board)):
- # 同列是否重复
- if self.board[idx][col] == str(target):
- return False
- # 同行是否重复
- if self.board[row][idx] == str(target):
- return False
- # 9宫格里是否重复
- box_row, box_col = (row // 3) * 3 + idx // 3, (col // 3) * 3 + idx % 3
- if self.board[box_row][box_col] == str(target):
- return False
return True
-
- def getPlace(self) -> List[int]:
- for row in range(len(self.board)):
- for col in range(len(self.board)):
- if self.board[row][col] == ".":
- return [row, col]
- return [-1, -1]
-
- def isSolved(self) -> bool:
- row, col = self.getPlace() # 找个空位置
-
- if row == -1 and col == -1: # 没有空位置,棋盘被填满的
- return True
-
- for i in range(1, 10):
- if self.isValid(row, col, i): # 检查这个空位置放i,是否合适
- self.board[row][col] = str(i) # 放i
- if self.isSolved(): # 合适,立刻返回, 填下一个空位置。
- return True
- self.board[row][col] = "." # 不合适,回溯
-
- return False # 空位置没法解决
-
- def solveSudoku(self, board: List[List[str]]) -> None:
- """
- Do not return anything, modify board in-place instead.
- """
- if board is None or len(board) == 0:
- return
- self.board = board
- self.isSolved()
```
Go:
From b64e34815dc60ba7b0a2450a7bcf7cd723ec0abc Mon Sep 17 00:00:00 2001
From: Henry Du
Date: Tue, 12 Oct 2021 18:27:06 -0700
Subject: [PATCH 239/284] =?UTF-8?q?Add=20Go=20into=20337.=E6=89=93?=
=?UTF-8?q?=E5=AE=B6=E5=8A=AB=E8=88=8DIII.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0337.打家劫舍III.md | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/problems/0337.打家劫舍III.md b/problems/0337.打家劫舍III.md
index 949137c3..8456adf1 100644
--- a/problems/0337.打家劫舍III.md
+++ b/problems/0337.打家劫舍III.md
@@ -368,6 +368,41 @@ class Solution:
return (val1, val2)
```
+Go:
+
+> 动态规划
+
+```go
+func rob(root *TreeNode) int {
+ res := robTree(root)
+ return max(res[0], res[1])
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+func robTree(cur *TreeNode) []int {
+ if cur == nil {
+ return []int{0, 0}
+ }
+ // 后序遍历
+ left := robTree(cur.Left)
+ right := robTree(cur.Right)
+
+ // 考虑去偷当前的屋子
+ robCur := cur.Val + left[0] + right[0]
+ // 考虑不去偷当前的屋子
+ notRobCur := max(left[0], left[1]) + max(right[0], right[1])
+
+ // 注意顺序:0:不偷,1:去偷
+ return []int{notRobCur, robCur}
+}
+```
+
JavaScript:
> 动态规划
From 7484ba1e003679facc73922ab3d9eb1c909febce Mon Sep 17 00:00:00 2001
From: BarneyShi
Date: Tue, 12 Oct 2021 23:06:12 -0700
Subject: [PATCH 240/284] =?UTF-8?q?=E5=89=91=E6=8C=87Offer=2058=20-=20?=
=?UTF-8?q?=E4=B8=8D=E4=BD=BF=E7=94=A8=E9=A2=9D=E5=A4=96=E7=A9=BA=E9=97=B4?=
=?UTF-8?q?=E7=9A=84JS=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/剑指Offer58-II.左旋转字符串.md | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/problems/剑指Offer58-II.左旋转字符串.md b/problems/剑指Offer58-II.左旋转字符串.md
index 29243c6d..60f7115d 100644
--- a/problems/剑指Offer58-II.左旋转字符串.md
+++ b/problems/剑指Offer58-II.左旋转字符串.md
@@ -200,17 +200,14 @@ func reverse(b []byte, left, right int){
JavaScript:
```javascript
-var reverseLeftWords = function (s, n) {
- const reverse = (str, left, right) => {
- let strArr = str.split("");
- for (; left < right; left++, right--) {
- [strArr[left], strArr[right]] = [strArr[right], strArr[left]];
- }
- return strArr.join("");
- }
- s = reverse(s, 0, n - 1);
- s = reverse(s, n, s.length - 1);
- return reverse(s, 0, s.length - 1);
+var reverseLeftWords = function(s, n) {
+ const length = s.length;
+ let i = 0;
+ while (i < length - n) {
+ s = s[length - 1] + s;
+ i++;
+ }
+ return s.slice(0, length);
};
```
From 5c69042ea2f4238617868a785e6ab51946c7d813 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98Carl?=
Date: Thu, 14 Oct 2021 09:53:25 +0800
Subject: [PATCH 241/284] =?UTF-8?q?Update=20=E7=AE=97=E6=B3=95=E6=A8=A1?=
=?UTF-8?q?=E6=9D=BF.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/算法模板.md | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/problems/算法模板.md b/problems/算法模板.md
index c772c178..216ae6b6 100644
--- a/problems/算法模板.md
+++ b/problems/算法模板.md
@@ -8,7 +8,7 @@
## 二分查找法
-```c++
+```CPP
class Solution {
public:
int searchInsert(vector& nums, int target) {
@@ -33,7 +33,7 @@ public:
## KMP
-```c++
+```CPP
void kmp(int* next, const string& s){
next[0] = -1;
int j = -1;
@@ -53,7 +53,7 @@ void kmp(int* next, const string& s){
二叉树的定义:
-```c++
+```CPP
struct TreeNode {
int val;
TreeNode *left;
@@ -65,7 +65,7 @@ struct TreeNode {
### 深度优先遍历(递归)
前序遍历(中左右)
-```c++
+```CPP
void traversal(TreeNode* cur, vector& vec) {
if (cur == NULL) return;
vec.push_back(cur->val); // 中 ,同时也是处理节点逻辑的地方
@@ -74,7 +74,7 @@ void traversal(TreeNode* cur, vector& vec) {
}
```
中序遍历(左中右)
-```c++
+```CPP
void traversal(TreeNode* cur, vector& vec) {
if (cur == NULL) return;
traversal(cur->left, vec); // 左
@@ -83,7 +83,7 @@ void traversal(TreeNode* cur, vector& vec) {
}
```
后序遍历(左右中)
-```c++
+```CPP
void traversal(TreeNode* cur, vector& vec) {
if (cur == NULL) return;
traversal(cur->left, vec); // 左
@@ -97,7 +97,7 @@ void traversal(TreeNode* cur, vector& vec) {
相关题解:[0094.二叉树的中序遍历](https://github.com/youngyangyang04/leetcode/blob/master/problems/0094.二叉树的中序遍历.md)
前序遍历(中左右)
-```c++
+```CPP
vector preorderTraversal(TreeNode* root) {
vector result;
stack st;
@@ -123,7 +123,7 @@ vector preorderTraversal(TreeNode* root) {
```
中序遍历(左中右)
-```c++
+```CPP
vector inorderTraversal(TreeNode* root) {
vector result; // 存放中序遍历的元素
stack st;
@@ -148,7 +148,7 @@ vector inorderTraversal(TreeNode* root) {
```
后序遍历(左右中)
-```c++
+```CPP
vector postorderTraversal(TreeNode* root) {
vector result;
stack st;
@@ -176,7 +176,7 @@ vector postorderTraversal(TreeNode* root) {
相关题解:[0102.二叉树的层序遍历](https://programmercarl.com/0102.二叉树的层序遍历.html)
-```c++
+```CPP
vector> levelOrder(TreeNode* root) {
queue que;
if (root != NULL) que.push(root);
@@ -212,7 +212,7 @@ vector> levelOrder(TreeNode* root) {
### 二叉树深度
-```c++
+```CPP
int getDepth(TreeNode* node) {
if (node == NULL) return 0;
return 1 + max(getDepth(node->left), getDepth(node->right));
@@ -221,7 +221,7 @@ int getDepth(TreeNode* node) {
### 二叉树节点数量
-```c++
+```CPP
int countNodes(TreeNode* root) {
if (root == NULL) return 0;
return 1 + countNodes(root->left) + countNodes(root->right);
@@ -229,7 +229,7 @@ int countNodes(TreeNode* root) {
```
## 回溯算法
-```c++
+```CPP
void backtracking(参数) {
if (终止条件) {
存放结果;
@@ -247,7 +247,7 @@ void backtracking(参数) {
## 并查集
-```c++
+```CPP
int n = 1005; // 更具题意而定
int father[1005];
From aedda8732e662a76a4d4e6916da0f31230487889 Mon Sep 17 00:00:00 2001
From: hailincai
Date: Thu, 14 Oct 2021 07:16:33 -0400
Subject: [PATCH 242/284] =?UTF-8?q?Update=200707.=E8=AE=BE=E8=AE=A1?=
=?UTF-8?q?=E9=93=BE=E8=A1=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Format the ListNode definition for java code
---
problems/0707.设计链表.md | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/problems/0707.设计链表.md b/problems/0707.设计链表.md
index 64472506..ba0e7e3b 100644
--- a/problems/0707.设计链表.md
+++ b/problems/0707.设计链表.md
@@ -282,12 +282,12 @@ Java:
```Java
//单链表
class ListNode {
-int val;
-ListNode next;
-ListNode(){}
-ListNode(int val) {
-this.val=val;
-}
+ int val;
+ ListNode next;
+ ListNode(){}
+ ListNode(int val) {
+ this.val=val;
+ }
}
class MyLinkedList {
//size存储链表元素的个数
From e037b8755822d926de2b44eff180824f2baa4b7c Mon Sep 17 00:00:00 2001
From: hailincai
Date: Thu, 14 Oct 2021 07:58:33 -0400
Subject: [PATCH 243/284] =?UTF-8?q?Update=200206.=E7=BF=BB=E8=BD=AC?=
=?UTF-8?q?=E9=93=BE=E8=A1=A8.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
增加Java从后向前递归的代码
---
problems/0206.翻转链表.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index ec6f3dca..3e2a22be 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -164,6 +164,25 @@ class Solution {
}
```
+```java
+// 从后向前递归
+class Solution {
+ ListNode reverseList(ListNode head) {
+ // 边缘条件判断
+ if(head == null) return null;
+ if (head.next == null) return head;
+
+ // 递归调用,翻转第二个节点开始往后的链表
+ ListNode last = reverseList(head.next);
+ // 翻转头节点与第二个节点的指向
+ head.next.next = head;
+ // 此时的 head 节点为尾节点,next 需要指向 NULL
+ head.next = null;
+ return last;
+ }
+}
+```
+
Python迭代法:
```python
#双指针
From 99d28fcc002dc5bb40952f01d3c975ec46b867b5 Mon Sep 17 00:00:00 2001
From: baici1 <249337001@qq.com>
Date: Fri, 15 Oct 2021 16:21:58 +0800
Subject: [PATCH 244/284] =?UTF-8?q?337.=E6=89=93=E5=AE=B6=E5=8A=AB?=
=?UTF-8?q?=E8=88=8D=E2=85=A2=20=E5=A2=9E=E5=8A=A0go=E7=9A=84=E8=A7=A3?=
=?UTF-8?q?=E6=B3=95=20=E6=A0=91=E5=BD=A2DP?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0337.打家劫舍III.md | 42 ++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/problems/0337.打家劫舍III.md b/problems/0337.打家劫舍III.md
index 949137c3..204c3815 100644
--- a/problems/0337.打家劫舍III.md
+++ b/problems/0337.打家劫舍III.md
@@ -368,6 +368,48 @@ class Solution:
return (val1, val2)
```
+Go:
+
+树形DP
+
+```go
+/**
+ * Definition for a binary tree node.
+ * type TreeNode struct {
+ * Val int
+ * Left *TreeNode
+ * Right *TreeNode
+ * }
+ */
+func rob(root *TreeNode) int {
+ return max(robTree(root))
+}
+func robTree(root *TreeNode)(int,int){
+ if root==nil{
+ return 0,0
+ }
+ //获取左节点的偷的值与不偷的值
+ left0,left1:=robTree(root.Left)
+ //获取右节点的偷的值与不偷的值
+ right0,right1:=robTree(root.Right)
+ //偷
+ val1:=root.Val
+ val1+=left1+right1
+ //不偷
+ val2:=0
+ val2+=max(left0,left1)+max(right0,right1)
+ return val1,val2
+}
+func max(a,b int)int{
+ if a>b{
+ return a
+ }
+ return b
+}
+```
+
+
+
JavaScript:
> 动态规划
From 77d346988b1718b34f4997e7d08be82c418edd6b Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Fri, 15 Oct 2021 20:16:39 +0800
Subject: [PATCH 245/284] =?UTF-8?q?=E6=94=B9=E8=BF=9B=200143=20=E9=87=8D?=
=?UTF-8?q?=E6=8E=92=E9=93=BE=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
在使用数组存储链表节点的写法中,最后再判断数组长度为偶数时时没有必要的,因为在循环体while里面,我们用的是 i<=j。
---
problems/0143.重排链表.md | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/problems/0143.重排链表.md b/problems/0143.重排链表.md
index c5ac9bae..a6412d2e 100644
--- a/problems/0143.重排链表.md
+++ b/problems/0143.重排链表.md
@@ -50,10 +50,6 @@ public:
cur = cur->next;
count++;
}
- if (vec.size() % 2 == 0) { // 如果是偶数,还要多处理中间的一个
- cur->next = vec[i];
- cur = cur->next;
- }
cur->next = nullptr; // 注意结尾
}
};
@@ -249,12 +245,6 @@ public class ReorderList {
cur = cur.next;
count++;
}
- // 当是偶数的话,需要做额外处理
- if (list.size() % 2== 0){
- cur.next = list.get(l);
- cur = cur.next;
- }
-
// 注意结尾要结束一波
cur.next = null;
}
@@ -376,11 +366,6 @@ var reorderList = function(head, s = [], tmp) {
cur = cur.next;
count++;
}
- // 当是偶数的话,需要做额外处理
- if(list.length % 2 == 0){
- cur.next = list[l];
- cur = cur.next;
- }
// 注意结尾要结束一波
cur.next = null;
}
From 5d0d80abc978a01c2b5f6f17583f890ece8988ea Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Fri, 15 Oct 2021 21:33:20 +0800
Subject: [PATCH 246/284] =?UTF-8?q?=E7=AE=97=E6=B3=95=E6=A8=A1=E6=9D=BF=20?=
=?UTF-8?q?=20=E6=B7=BB=E5=8A=A0=20JavaScript=20=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/算法模板.md | 259 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 258 insertions(+), 1 deletion(-)
diff --git a/problems/算法模板.md b/problems/算法模板.md
index 216ae6b6..9fa4f1a8 100644
--- a/problems/算法模板.md
+++ b/problems/算法模板.md
@@ -248,7 +248,7 @@ void backtracking(参数) {
## 并查集
```CPP
- int n = 1005; // 更具题意而定
+ int n = 1005; // 根据题意而定
int father[1005];
// 并查集初始化
@@ -280,6 +280,263 @@ void backtracking(参数) {
(持续补充ing)
## 其他语言版本
+JavaScript:
+
+## 二分查找法
+
+使用左闭右闭区间
+
+```javascript
+var search = function (nums, target) {
+ let left = 0, right = nums.length - 1;
+ // 使用左闭右闭区间
+ while (left <= right) {
+ let mid = left + Math.floor((right - left)/2);
+ if (nums[mid] > target) {
+ right = mid - 1; // 去左面闭区间寻找
+ } else if (nums[mid] < target) {
+ left = mid + 1; // 去右面闭区间寻找
+ } else {
+ return mid;
+ }
+ }
+ return -1;
+};
+```
+
+使用左闭右开区间
+
+```javascript
+var search = function (nums, target) {
+ let left = 0, right = nums.length;
+ // 使用左闭右开区间 [left, right)
+ while (left < right) {
+ let mid = left + Math.floor((right - left)/2);
+ if (nums[mid] > target) {
+ right = mid; // 去左面闭区间寻找
+ } else if (nums[mid] < target) {
+ left = mid + 1; // 去右面闭区间寻找
+ } else {
+ return mid;
+ }
+ }
+ return -1;
+};
+```
+
+## KMP
+
+```javascript
+var kmp = function (next, s) {
+ next[0] = -1;
+ let j = -1;
+ for(let i = 1; i < s.length; i++){
+ while (j >= 0 && s[i] !== s[j + 1]) {
+ j = next[j];
+ }
+ if (s[i] === s[j + 1]) {
+ j++;
+ }
+ next[i] = j;
+ }
+}
+```
+
+## 二叉树
+
+### 深度优先遍历(递归)
+
+二叉树节点定义:
+
+```javascript
+function TreeNode (val, left, right) {
+ this.val = (val === undefined ? 0 : val);
+ this.left = (left === undefined ? null : left);
+ this.right = (right === undefined ? null : right);
+}
+```
+
+前序遍历(中左右):
+
+```javascript
+var preorder = function (root, list) {
+ if (root === null) return;
+ list.push(root.val); // 中
+ preorder(root.left, list); // 左
+ preorder(root.right, list); // 右
+}
+```
+
+中序遍历(左中右):
+
+```javascript
+var inorder = function (root, list) {
+ if (root === null) return;
+ inorder(root.left, list); // 左
+ list.push(root.val); // 中
+ inorder(root.right, list); // 右
+}
+```
+
+后序遍历(左右中):
+
+```javascript
+var postorder = function (root, list) {
+ if (root === null) return;
+ postorder(root.left, list); // 左
+ postorder(root.right, list); // 右
+ list.push(root.val); // 中
+}
+```
+
+### 深度优先遍历(迭代)
+
+前序遍历(中左右):
+
+```javascript
+var preorderTraversal = function (root) {
+ let res = [];
+ if (root === null) return rs;
+ let stack = [root],
+ cur = null;
+ while (stack.length) {
+ cur = stack.pop();
+ res.push(cur.val);
+ cur.right && stack.push(cur.right);
+ cur.left && stack.push(cur.left);
+ }
+ return res;
+};
+```
+
+中序遍历(左中右):
+
+```javascript
+var inorderTraversal = function (root) {
+ let res = [];
+ if (root === null) return res;
+ let stack = [];
+ let cur = root;
+ while (stack.length !== 0 || cur !== null) {
+ if (cur !== null) {
+ stack.push(cur);
+ cur = cur.left;
+ } else {
+ cur = stack.pop();
+ res.push(cur.val);
+ cur = cur.right;
+ }
+ }
+ return res;
+};
+```
+
+后序遍历(左右中):
+
+```javascript
+var postorderTraversal = function (root) {
+ let res = [];
+ if (root === null) return res;
+ let stack = [root];
+ let cur = null;
+ while (stack.length) {
+ cur = stack.pop();
+ res.push(cur.val);
+ cur.left && stack.push(cur.left);
+ cur.right && stack.push(cur.right);
+ }
+ return res.reverse()
+};
+```
+
+### 广度优先遍历(队列)
+
+```javascript
+var levelOrder = function (root) {
+ let res = [];
+ if (root === null) return res;
+ let queue = [root];
+ while (queue.length) {
+ let n = queue.length;
+ let temp = [];
+ for (let i = 0; i < n; i++) {
+ let node = queue.shift();
+ temp.push(node.val);
+ node.left &&queue.push(node.left);
+ node.right && queue.push(node.right);
+ }
+ res.push(temp);
+ }
+ return res;
+};
+```
+
+### 二叉树深度
+
+```javascript
+var getDepth = function (node) {
+ if (node === null) return 0;
+ return 1 + Math.max(getDepth(node.left), getDepth(node.right));
+}
+```
+
+### 二叉树节点数量
+
+```javascript
+var countNodes = function (root) {
+ if (root === null) return 0;
+ return 1 + countNodes(root.left) + countNodes(root.right);
+}
+```
+
+## 回溯算法
+
+```javascript
+function backtracking(参数) {
+ if (终止条件) {
+ 存放结果;
+ return;
+ }
+
+ for (选择:本层集合中元素(树中节点孩子的数量就是集合的大小)) {
+ 处理节点;
+ backtracking(路径,选择列表); // 递归
+ 回溯,撤销处理结果
+ }
+}
+
+```
+
+## 并查集
+
+```javascript
+ let n = 1005; // 根据题意而定
+ let father = new Array(n).fill(0);
+
+ // 并查集初始化
+ function init () {
+ for (int i = 0; i < n; ++i) {
+ father[i] = i;
+ }
+ }
+ // 并查集里寻根的过程
+ function find (u) {
+ return u === father[u] ? u : father[u] = find(father[u]);
+ }
+ // 将v->u 这条边加入并查集
+ function join(u, v) {
+ u = find(u);
+ v = find(v);
+ if (u === v) return ;
+ father[v] = u;
+ }
+ // 判断 u 和 v是否找到同一个根
+ function same(u, v) {
+ u = find(u);
+ v = find(v);
+ return u === v;
+ }
+```
Java:
From ebe4ea6db537c74ef03d10b6d1bda283c6cf522d Mon Sep 17 00:00:00 2001
From: KailokFung
Date: Sat, 16 Oct 2021 22:28:53 +0800
Subject: [PATCH 247/284] =?UTF-8?q?fix(0135):=20=E5=8A=A0=E4=BA=86?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A=EF=BC=8C=E6=AF=94=E5=8E=9F=E5=85=88=E5=B0=91?=
=?UTF-8?q?=E4=B8=80=E6=AC=A1=E9=81=8D=E5=8E=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0135.分发糖果.md | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/problems/0135.分发糖果.md b/problems/0135.分发糖果.md
index ace6bc7d..f3c00536 100644
--- a/problems/0135.分发糖果.md
+++ b/problems/0135.分发糖果.md
@@ -132,30 +132,33 @@ public:
Java:
```java
class Solution {
+ /**
+ 分两个阶段
+ 1、起点下标1 从左往右,只要 右边 比 左边 大,右边的糖果=左边 + 1
+ 2、起点下标 ratings.length - 2 从右往左, 只要左边 比 右边 大,此时 左边的糖果应该 取本身的糖果数(符合比它左边大) 和 右边糖果数 + 1 二者的最大值,这样才符合 它比它左边的大,也比它右边大
+ */
public int candy(int[] ratings) {
- int[] candy = new int[ratings.length];
- for (int i = 0; i < candy.length; i++) {
- candy[i] = 1;
- }
-
+ int[] candyVec = new int[ratings.length];
+ candyVec[0] = 1;
for (int i = 1; i < ratings.length; i++) {
if (ratings[i] > ratings[i - 1]) {
- candy[i] = candy[i - 1] + 1;
+ candyVec[i] = candyVec[i - 1] + 1;
+ } else {
+ candyVec[i] = 1;
}
}
for (int i = ratings.length - 2; i >= 0; i--) {
if (ratings[i] > ratings[i + 1]) {
- candy[i] = Math.max(candy[i],candy[i + 1] + 1);
+ candyVec[i] = Math.max(candyVec[i], candyVec[i + 1] + 1);
}
}
- int count = 0;
- for (int i = 0; i < candy.length; i++) {
- count += candy[i];
+ int ans = 0;
+ for (int s : candyVec) {
+ ans += s;
}
-
- return count;
+ return ans;
}
}
```
From d92d7207cb8ec4d8628c41e8aaeca6145ca76823 Mon Sep 17 00:00:00 2001
From: Luo <82520819+Jerry-306@users.noreply.github.com>
Date: Sun, 17 Oct 2021 10:20:19 +0800
Subject: [PATCH 248/284] =?UTF-8?q?=E7=AE=80=E5=8C=96=201002=20=E6=9F=A5?=
=?UTF-8?q?=E6=89=BE=E7=9B=B8=E5=90=8C=E5=AD=97=E7=AC=A6=20JavaScript?=
=?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
对两个数组的初值写法进行简化
---
problems/1002.查找常用字符.md | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md
index 09e49c4f..44a02ceb 100644
--- a/problems/1002.查找常用字符.md
+++ b/problems/1002.查找常用字符.md
@@ -224,10 +224,7 @@ javaScript
var commonChars = function (words) {
let res = []
let size = 26
- let firstHash = new Array(size)
- for (let i = 0; i < size; i++) { // 初始化 hash 数组
- firstHash[i] = 0
- }
+ let firstHash = new Array(size).fill(0) // 初始化 hash 数组
let a = "a".charCodeAt()
let firstWord = words[0]
@@ -235,21 +232,20 @@ var commonChars = function (words) {
let idx = firstWord[i].charCodeAt()
firstHash[idx - a] += 1
}
-
+
+ let otherHash = new Array(size).fill(0) // 初始化 hash 数组
for (let i = 1; i < words.length; i++) { // 1-n 个单词统计
- let otherHash = new Array(size)
- for (let i = 0; i < size; i++) { // 初始化 hash 数组
- otherHash[i] = 0
- }
-
for (let j = 0; j < words[i].length; j++) {
let idx = words[i][j].charCodeAt()
otherHash[idx - a] += 1
}
+
for (let i = 0; i < size; i++) {
firstHash[i] = Math.min(firstHash[i], otherHash[i])
}
+ otherHash.fill(0)
}
+
for (let i = 0; i < size; i++) {
while (firstHash[i] > 0) {
res.push(String.fromCharCode(i + a))
From a20e8cb7626e0d238c7aee8029d60bbf1d938936 Mon Sep 17 00:00:00 2001
From: Junwen Huang
Date: Sun, 17 Oct 2021 11:18:30 +0800
Subject: [PATCH 249/284] =?UTF-8?q?update=EF=BC=9A20200927=E4=BA=8C?=
=?UTF-8?q?=E5=8F=89=E6=A0=91=E5=91=A8=E6=9C=AB=E6=80=BB=E7=BB=93.md=20-?=
=?UTF-8?q?=20=20=E8=A1=A5=E5=85=85=E9=A2=98=E7=9B=AE=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充题目链接
---
problems/周总结/20200927二叉树周末总结.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/problems/周总结/20200927二叉树周末总结.md b/problems/周总结/20200927二叉树周末总结.md
index 5a7e398a..ff8f67d4 100644
--- a/problems/周总结/20200927二叉树周末总结.md
+++ b/problems/周总结/20200927二叉树周末总结.md
@@ -51,8 +51,8 @@ morris遍历是二叉树遍历算法的超强进阶算法,morris遍历可以
在[二叉树:一入递归深似海,从此offer是路人](https://programmercarl.com/二叉树的递归遍历.html)中讲到了递归三要素,以及前中后序的递归写法。
文章中我给出了leetcode上三道二叉树的前中后序题目,但是看完[二叉树:一入递归深似海,从此offer是路人](https://programmercarl.com/二叉树的递归遍历.html),依然可以解决n叉树的前后序遍历,在leetcode上分别是
-* 589. N叉树的前序遍历
-* 590. N叉树的后序遍历
+* [589. N叉树的前序遍历](https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/)
+* [590. N叉树的后序遍历](https://leetcode-cn.com/problems/n-ary-tree-postorder-traversal/)
大家可以再去把这两道题目做了。
From cb9a717a7ccdbb6063837a231b7a1a1d45258772 Mon Sep 17 00:00:00 2001
From: KailokFung
Date: Mon, 18 Oct 2021 11:01:38 +0800
Subject: [PATCH 250/284] =?UTF-8?q?fix(0763):=20=E4=B8=8B=E6=A0=87?=
=?UTF-8?q?=E5=8F=96=20=E5=AD=97=E6=AF=8D=20-=20'a'=20=E7=9A=84=E5=80=BC?=
=?UTF-8?q?=EF=BC=8C=E5=B0=91=E7=82=B9=E7=A9=BA=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0763.划分字母区间.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md
index 863b569d..c64ff3c8 100644
--- a/problems/0763.划分字母区间.md
+++ b/problems/0763.划分字母区间.md
@@ -88,15 +88,15 @@ Java:
class Solution {
public List partitionLabels(String S) {
List list = new LinkedList<>();
- int[] edge = new int[123];
+ int[] edge = new int[26];
char[] chars = S.toCharArray();
for (int i = 0; i < chars.length; i++) {
- edge[chars[i] - 0] = i;
+ edge[chars[i] - 'a'] = i;
}
int idx = 0;
int last = -1;
for (int i = 0; i < chars.length; i++) {
- idx = Math.max(idx,edge[chars[i] - 0]);
+ idx = Math.max(idx,edge[chars[i] - 'a']);
if (i == idx) {
list.add(i - last);
last = i;
From 8a39e604920718c9fffd8eaf2d7b26741a5b0df6 Mon Sep 17 00:00:00 2001
From: YuanPei Li
Date: Wed, 20 Oct 2021 10:56:21 +0800
Subject: [PATCH 251/284] fix typo
---
problems/0977.有序数组的平方.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0977.有序数组的平方.md b/problems/0977.有序数组的平方.md
index 0d9f2ac1..883b2f16 100644
--- a/problems/0977.有序数组的平方.md
+++ b/problems/0977.有序数组的平方.md
@@ -27,7 +27,7 @@
## 暴力排序
-最直观的相反,莫过于:每个数平方之后,排个序,美滋滋,代码如下:
+最直观的想法,莫过于:每个数平方之后,排个序,美滋滋,代码如下:
```CPP
class Solution {
From 21ee536593567244e3f75d1c0072b2e4251ad7f7 Mon Sep 17 00:00:00 2001
From: sugarlesss
Date: Wed, 20 Oct 2021 11:02:47 +0800
Subject: [PATCH 252/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200019.=E5=88=A0?=
=?UTF-8?q?=E9=99=A4=E9=93=BE=E8=A1=A8=E7=9A=84=E5=80=92=E6=95=B0=E7=AC=AC?=
=?UTF-8?q?N=E4=B8=AA=E8=8A=82=E7=82=B9=20=E6=96=87=E7=AB=A0=E9=94=99?=
=?UTF-8?q?=E5=88=AB=E5=AD=97=E5=8B=98=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0019.删除链表的倒数第N个节点.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0019.删除链表的倒数第N个节点.md b/problems/0019.删除链表的倒数第N个节点.md
index 0e8aeaec..fe68d999 100644
--- a/problems/0019.删除链表的倒数第N个节点.md
+++ b/problems/0019.删除链表的倒数第N个节点.md
@@ -50,7 +50,7 @@
* fast首先走n + 1步 ,为什么是n+1呢,因为只有这样同时移动的时候slow才能指向删除节点的上一个节点(方便做删除操作),如图:
-* fast和slow同时移动,之道fast指向末尾,如题:
+* fast和slow同时移动,直到fast指向末尾,如题:
* 删除slow指向的下一个节点,如图:
From 68f6c46a1434bedd732f24c082ff920f81fd9e88 Mon Sep 17 00:00:00 2001
From: Jhonson
Date: Wed, 20 Oct 2021 21:30:30 +0800
Subject: [PATCH 253/284] =?UTF-8?q?[=E5=9B=9E=E6=BA=AF=E7=AE=97=E6=B3=95?=
=?UTF-8?q?=E5=8E=BB=E9=87=8D=E9=97=AE=E9=A2=98=E7=9A=84=E5=8F=A6=E4=B8=80?=
=?UTF-8?q?=E7=A7=8D=E5=86=99=E6=B3=95.md]=20add=20python=20code?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/回溯算法去重问题的另一种写法.md | 77 +++++++++++++++++++++++-
1 file changed, 76 insertions(+), 1 deletion(-)
diff --git a/problems/回溯算法去重问题的另一种写法.md b/problems/回溯算法去重问题的另一种写法.md
index 8e92b95b..d8125e91 100644
--- a/problems/回溯算法去重问题的另一种写法.md
+++ b/problems/回溯算法去重问题的另一种写法.md
@@ -250,9 +250,84 @@ used数组可是全局变量,每层与每层之间公用一个used数组,所
Java:
-
Python:
+**90.子集II**
+
+```python
+class Solution:
+ def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
+ res = []
+ nums.sort()
+ def backtracking(start, path):
+ res.append(path)
+ uset = set()
+ for i in range(start, len(nums)):
+ if nums[i] not in uset:
+ backtracking(i + 1, path + [nums[i]])
+ uset.add(nums[i])
+
+ backtracking(0, [])
+ return res
+```
+
+**40. 组合总和 II**
+
+```python
+class Solution:
+ def combinationSum2(self, candidates: List[int], target: int) -> List[List[int]]:
+
+ res = []
+ candidates.sort()
+
+ def backtracking(start, path):
+ if sum(path) == target:
+ res.append(path)
+ elif sum(path) < target:
+ used = set()
+ for i in range(start, len(candidates)):
+ if candidates[i] in used:
+ continue
+ else:
+ used.add(candidates[i])
+ backtracking(i + 1, path + [candidates[i]])
+
+ backtracking(0, [])
+
+ return res
+```
+
+**47. 全排列 II**
+
+```python
+class Solution:
+ def permuteUnique(self, nums: List[int]) -> List[List[int]]:
+ path = []
+ res = []
+ used = [False]*len(nums)
+
+ def backtracking():
+ if len(path) == len(nums):
+ res.append(path.copy())
+
+ deduplicate = set()
+ for i, num in enumerate(nums):
+ if used[i] == True:
+ continue
+ if num in deduplicate:
+ continue
+ used[i] = True
+ path.append(nums[i])
+ backtracking()
+ used[i] = False
+ path.pop()
+ deduplicate.add(num)
+
+ backtracking()
+
+ return res
+```
+
Go:
From 5cb33c319b8652f2694fccc9db88127ce5f24563 Mon Sep 17 00:00:00 2001
From: Arthur
Date: Wed, 20 Oct 2021 16:10:04 +0100
Subject: [PATCH 254/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200106.=E4=BB=8E?=
=?UTF-8?q?=E4=B8=AD=E5=BA=8F=E4=B8=8E=E5=90=8E=E7=BB=AD=E9=81=8D=E5=8E=86?=
=?UTF-8?q?=E6=9E=84=E9=80=A0=E4=BA=8C=E5=8F=89=E6=A0=91.md=20C=E8=AF=AD?=
=?UTF-8?q?=E8=A8=80=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../0106.从中序与后序遍历序列构造二叉树.md | 75 +++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md
index 39b55d8c..9e0b2430 100644
--- a/problems/0106.从中序与后序遍历序列构造二叉树.md
+++ b/problems/0106.从中序与后序遍历序列构造二叉树.md
@@ -818,6 +818,81 @@ var buildTree = function(preorder, inorder) {
};
```
+## C
+106 从中序与后序遍历序列构造二叉树
+```c
+int linearSearch(int* arr, int arrSize, int key) {
+ int i;
+ for(i = 0; i < arrSize; i++) {
+ if(arr[i] == key)
+ return i;
+ }
+ return -1;
+}
+
+struct TreeNode* buildTree(int* inorder, int inorderSize, int* postorder, int postorderSize){
+ //若中序遍历数组中没有元素,则返回NULL
+ if(!inorderSize)
+ return NULL;
+ //创建一个新的结点,将node的val设置为后序遍历的最后一个元素
+ struct TreeNode* node = (struct TreeNode*)malloc(sizeof(struct TreeNode));
+ node->val = postorder[postorderSize - 1];
+
+ //通过线性查找找到中间结点在中序数组中的位置
+ int index = linearSearch(inorder, inorderSize, postorder[postorderSize - 1]);
+
+ //左子树数组大小为index
+ //右子树的数组大小为数组大小减index减1(减的1为中间结点)
+ int rightSize = inorderSize - index - 1;
+ node->left = buildTree(inorder, index, postorder, index);
+ node->right = buildTree(inorder + index + 1, rightSize, postorder + index, rightSize);
+ return node;
+}
+```
+
+105 从前序与中序遍历序列构造二叉树
+```c
+struct TreeNode* buildTree(int* preorder, int preorderSize, int* inorder, int inorderSize){
+ // 递归结束条件:传入的数组大小为0
+ if(!preorderSize)
+ return NULL;
+
+ // 1.找到前序遍历数组的第一个元素, 创建结点。左右孩子设置为NULL。
+ int rootValue = preorder[0];
+ struct TreeNode* root = (struct TreeNode*)malloc(sizeof(struct TreeNode));
+ root->val = rootValue;
+ root->left = NULL;
+ root->right = NULL;
+
+ // 2.若前序遍历数组的大小为1,返回该结点
+ if(preorderSize == 1)
+ return root;
+
+ // 3.根据该结点切割中序遍历数组,将中序遍历数组分割成左右两个数组。算出他们的各自大小
+ int index;
+ for(index = 0; index < inorderSize; index++) {
+ if(inorder[index] == rootValue)
+ break;
+ }
+ int leftNum = index;
+ int rightNum = inorderSize - index - 1;
+
+ int* leftInorder = inorder;
+ int* rightInorder = inorder + leftNum + 1;
+
+ // 4.根据中序遍历数组左右数组的各子大小切割前序遍历数组。也分为左右数组
+ int* leftPreorder = preorder+1;
+ int* rightPreorder = preorder + 1 + leftNum;
+
+ // 5.递归进入左右数组,将返回的结果作为根结点的左右孩子
+ root->left = buildTree(leftPreorder, leftNum, leftInorder, leftNum);
+ root->right = buildTree(rightPreorder, rightNum, rightInorder, rightNum);
+
+ // 6.返回根节点
+ return root;
+}
+```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From 8451af1e7804e97cb1ba597de10e7277596e0fcb Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Thu, 21 Oct 2021 11:13:08 +0800
Subject: [PATCH 255/284] =?UTF-8?q?Update=201356.=E6=A0=B9=E6=8D=AE?=
=?UTF-8?q?=E6=95=B0=E5=AD=97=E4=BA=8C=E8=BF=9B=E5=88=B6=E4=B8=8B1?=
=?UTF-8?q?=E7=9A=84=E6=95=B0=E7=9B=AE=E6=8E=92=E5=BA=8F.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
新增python代码
---
problems/1356.根据数字二进制下1的数目排序.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/problems/1356.根据数字二进制下1的数目排序.md b/problems/1356.根据数字二进制下1的数目排序.md
index a122df6f..b8b0245d 100644
--- a/problems/1356.根据数字二进制下1的数目排序.md
+++ b/problems/1356.根据数字二进制下1的数目排序.md
@@ -156,6 +156,17 @@ class Solution {
## Python
```python
+class Solution:
+ def sortByBits(self, arr: List[int]) -> List[int]:
+ arr.sort(key=lambda num: (self.count_bits(num), num))
+ return arr
+
+ def count_bits(self, num: int) -> int:
+ count = 0
+ while num:
+ num &= num - 1
+ count += 1
+ return count
```
## Go
From 75e1bb2e7ba1c5334b30068882db8c27cf078982 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Thu, 21 Oct 2021 12:54:24 +0800
Subject: [PATCH 256/284] =?UTF-8?q?Update=200031.=E4=B8=8B=E4=B8=80?=
=?UTF-8?q?=E4=B8=AA=E6=8E=92=E5=88=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
新增python代码:
抛砖引玉:因题目要求“必须原地修改,只允许使用额外常数空间”,python内置sorted函数以及数组切片+sort()无法使用,故选择另一种算法暂且提供一种python思路
---
problems/0031.下一个排列.md | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/problems/0031.下一个排列.md b/problems/0031.下一个排列.md
index 9efcb06a..470c354d 100644
--- a/problems/0031.下一个排列.md
+++ b/problems/0031.下一个排列.md
@@ -122,6 +122,33 @@ class Solution {
## Python
```python
+class Solution:
+ '''
+ 抛砖引玉:因题目要求“必须原地修改,只允许使用额外常数空间”,python内置sorted函数以及数组切片+sort()无法使用。
+ 故选择另一种算法暂且提供一种python思路
+ '''
+ def nextPermutation(self, nums: List[int]) -> None:
+ """
+ Do not return anything, modify nums in-place instead.
+ """
+ length = len(nums)
+ for i in range(length-1, 0, -1):
+ if nums[i-1] < nums[i]:
+ for j in range(length-1, 0, -1):
+ if nums[j] > nums[i-1]:
+ nums[i-1], nums[j] = nums[j], nums[i-1]
+ break
+ self.reverse(nums, i, length-1)
+ break
+ else:
+ # 若正常结束循环,则对原数组直接翻转
+ self.reverse(nums, 0, length-1)
+
+ def reverse(self, nums: List[int], low: int, high: int) -> None:
+ while low < high:
+ nums[low], nums[high] = nums[high], nums[low]
+ low += 1
+ high -= 1
```
## Go
From 1598341473568669dae56e3c1e84bef56f090147 Mon Sep 17 00:00:00 2001
From: Asterisk <44215173+casnz1601@users.noreply.github.com>
Date: Thu, 21 Oct 2021 12:58:03 +0800
Subject: [PATCH 257/284] =?UTF-8?q?Update=200031.=E4=B8=8B=E4=B8=80?=
=?UTF-8?q?=E4=B8=AA=E6=8E=92=E5=88=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
补充python sorted()代码
---
problems/0031.下一个排列.md | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/problems/0031.下一个排列.md b/problems/0031.下一个排列.md
index 470c354d..9999486e 100644
--- a/problems/0031.下一个排列.md
+++ b/problems/0031.下一个排列.md
@@ -120,7 +120,22 @@ class Solution {
```
## Python
-
+>直接使用sorted()不符合题意
+```python
+class Solution:
+ def nextPermutation(self, nums: List[int]) -> None:
+ """
+ Do not return anything, modify nums in-place instead.
+ """
+ for i in range(len(nums)-1, -1, -1):
+ for j in range(len(nums)-1, i, -1):
+ if nums[j] > nums[i]:
+ nums[j], nums[i] = nums[i], nums[j]
+ nums[i+1:len(nums)] = sorted(nums[i+1:len(nums)])
+ return
+ nums.sort()
+```
+>另一种思路
```python
class Solution:
'''
From 8f1fe3c1b747716d98f22e4f14b2e25e94a108d1 Mon Sep 17 00:00:00 2001
From: Arthur
Date: Thu, 21 Oct 2021 15:10:36 +0100
Subject: [PATCH 258/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200206.=E7=BF=BB?=
=?UTF-8?q?=E8=BD=AC=E9=93=BE=E8=A1=A8.md=20C=E8=AF=AD=E8=A8=80=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0206.翻转链表.md | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/problems/0206.翻转链表.md b/problems/0206.翻转链表.md
index 45196386..08495259 100644
--- a/problems/0206.翻转链表.md
+++ b/problems/0206.翻转链表.md
@@ -371,6 +371,45 @@ func reverse(pre: ListNode?, cur: ListNode?) -> ListNode? {
}
```
+C:
+双指针法:
+```c
+struct ListNode* reverseList(struct ListNode* head){
+ //保存cur的下一个结点
+ struct ListNode* temp;
+ //pre指针指向前一个当前结点的前一个结点
+ struct ListNode* pre = NULL;
+ //用head代替cur,也可以再定义一个cur结点指向head。
+ while(head) {
+ //保存下一个结点的位置
+ temp = head->next;
+ //翻转操作
+ head->next = pre;
+ //更新结点
+ pre = head;
+ head = temp;
+ }
+ return pre;
+}
+```
+
+递归法:
+```c
+struct ListNode* reverse(struct ListNode* pre, struct ListNode* cur) {
+ if(!cur)
+ return pre;
+ struct ListNode* temp = cur->next;
+ cur->next = pre;
+ //将cur作为pre传入下一层
+ //将temp作为cur传入下一层,改变其指针指向当前cur
+ return reverse(cur, temp);
+}
+
+struct ListNode* reverseList(struct ListNode* head){
+ return reverse(NULL, head);
+}
+```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From 712ab9aa00a830eb0ef6b09ec8b20f2a9050b7da Mon Sep 17 00:00:00 2001
From: Arthur
Date: Thu, 21 Oct 2021 15:31:22 +0100
Subject: [PATCH 259/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200226.=E7=BF=BB?=
=?UTF-8?q?=E8=BD=AC=E4=BA=8C=E5=8F=89=E6=A0=91.md=20C=E8=AF=AD=E8=A8=80?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0226.翻转二叉树.md | 45 +++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/problems/0226.翻转二叉树.md b/problems/0226.翻转二叉树.md
index b69cad55..d27d6d80 100644
--- a/problems/0226.翻转二叉树.md
+++ b/problems/0226.翻转二叉树.md
@@ -473,6 +473,51 @@ var invertTree = function(root) {
};
```
+C:
+递归法
+```c
+struct TreeNode* invertTree(struct TreeNode* root){
+ if(!root)
+ return NULL;
+ //交换结点的左右孩子(中)
+ struct TreeNode* temp = root->right;
+ root->right = root->left;
+ root->left = temp;
+ 左
+ invertTree(root->left);
+ //右
+ invertTree(root->right);
+ return root;
+}
+```
+迭代法:深度优先遍历
+```c
+struct TreeNode* invertTree(struct TreeNode* root){
+ if(!root)
+ return NULL;
+ //存储结点的栈
+ struct TreeNode** stack = (struct TreeNode**)malloc(sizeof(struct TreeNode*) * 100);
+ int stackTop = 0;
+ //将根节点入栈
+ stack[stackTop++] = root;
+ //若栈中还有元素(进行循环)
+ while(stackTop) {
+ //取出栈顶元素
+ struct TreeNode* temp = stack[--stackTop];
+ //交换结点的左右孩子
+ struct TreeNode* tempNode = temp->right;
+ temp->right = temp->left;
+ temp->left = tempNode;
+ //若当前结点有左右孩子,将其入栈
+ if(temp->right)
+ stack[stackTop++] = temp->right;
+ if(temp->left)
+ stack[stackTop++] = temp->left;
+ }
+ return root;
+}
+```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From 99dc8525256fb6f561ce7e47fc711bdac0e87363 Mon Sep 17 00:00:00 2001
From: changlua
Date: Thu, 21 Oct 2021 23:54:21 +0800
Subject: [PATCH 260/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=89=91?=
=?UTF-8?q?=E6=8C=87Offer05.=E6=9B=BF=E6=8D=A2=E7=A9=BA=E6=A0=BC=E7=9A=84j?=
=?UTF-8?q?ava=E5=8F=8C=E6=8C=87=E9=92=88=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/剑指Offer05.替换空格.md | 35 ++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/problems/剑指Offer05.替换空格.md b/problems/剑指Offer05.替换空格.md
index 232d1a0a..22789450 100644
--- a/problems/剑指Offer05.替换空格.md
+++ b/problems/剑指Offer05.替换空格.md
@@ -144,6 +144,41 @@ public static String replaceSpace(StringBuffer str) {
}
return sb.toString();
}
+
+//方式二:双指针法
+public String replaceSpace(String s) {
+ if(s == null || s.length() == 0){
+ return s;
+ }
+ //扩充空间,空格数量2倍
+ StringBuilder str = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) {
+ if(s.charAt(i) == ' '){
+ str.append(" ");
+ }
+ }
+ //若是没有空格直接返回
+ if(str.length() == 0){
+ return s;
+ }
+ //有空格情况 定义两个指针
+ int left = s.length() - 1;//左指针:指向原始字符串最后一个位置
+ s += str.toString();
+ int right = s.length()-1;//右指针:指向扩展字符串的最后一个位置
+ char[] chars = s.toCharArray();
+ while(left>=0){
+ if(chars[left] == ' '){
+ chars[right--] = '0';
+ chars[right--] = '2';
+ chars[right] = '%';
+ }else{
+ chars[right] = chars[left];
+ }
+ left--;
+ right--;
+ }
+ return new String(chars);
+}
```
From 35154b7be3d47785f77ec3680b71f2201fb2e9c1 Mon Sep 17 00:00:00 2001
From: baici1 <249337001@qq.com>
Date: Fri, 22 Oct 2021 16:58:02 +0800
Subject: [PATCH 261/284] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B9=B0=E5=8D=96?=
=?UTF-8?q?=E8=82=A1=E7=A5=A8=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA=E2=85=A1?=
=?UTF-8?q?=EF=BC=8C=E4=B9=B0=E5=8D=96=E8=82=A1=E7=A5=A8=E6=9C=80=E4=BD=B3?=
=?UTF-8?q?=E6=97=B6=E6=9C=BA=E2=85=A2=EF=BC=8C=E4=B9=B0=E5=8D=96=E8=82=A1?=
=?UTF-8?q?=E7=A5=A8=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA=E2=85=A3=20go?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../0122.买卖股票的最佳时机II(动态规划).md | 25 +++++++++++++
problems/0123.买卖股票的最佳时机III.md | 32 +++++++++++++++++
problems/0188.买卖股票的最佳时机IV.md | 36 +++++++++++++++++++
3 files changed, 93 insertions(+)
diff --git a/problems/0122.买卖股票的最佳时机II(动态规划).md b/problems/0122.买卖股票的最佳时机II(动态规划).md
index 4e64beaf..30c56c25 100644
--- a/problems/0122.买卖股票的最佳时机II(动态规划).md
+++ b/problems/0122.买卖股票的最佳时机II(动态规划).md
@@ -200,6 +200,31 @@ class Solution:
Go:
+```go
+func maxProfit(prices []int) int {
+ //创建数组
+ dp:=make([][]int,len(prices))
+ for i:=0;ib{
+ return a
+ }
+ return b
+}
+```
+
+
+
JavaScript:
> 版本一:
diff --git a/problems/0188.买卖股票的最佳时机IV.md b/problems/0188.买卖股票的最佳时机IV.md
index 5cffbe9e..a97f293a 100644
--- a/problems/0188.买卖股票的最佳时机IV.md
+++ b/problems/0188.买卖股票的最佳时机IV.md
@@ -276,6 +276,42 @@ class Solution:
```
Go:
+```go
+func maxProfit(k int, prices []int) int {
+ if len(prices)==0{
+ return 0
+ }
+ dp:=make([][]int,len(prices))
+ for i:=0;ib{
+ return a
+ }
+ return b
+}
+```
+
+
+
Javascript:
From 5a69916e0ff8c569b85090b6af97d9bddefff149 Mon Sep 17 00:00:00 2001
From: mengyuan
Date: Fri, 22 Oct 2021 17:26:47 +0800
Subject: [PATCH 262/284] =?UTF-8?q?update:=200202.=E5=BF=AB=E4=B9=90?=
=?UTF-8?q?=E6=95=B0=20js=E7=89=88=E6=9C=AC=20=E4=BD=BF=E7=94=A8Set()?=
=?UTF-8?q?=EF=BC=8C=E6=B1=82=E5=92=8C=E7=94=A8reduce?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0202.快乐数.md | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/problems/0202.快乐数.md b/problems/0202.快乐数.md
index 5704283d..d7a6b4e9 100644
--- a/problems/0202.快乐数.md
+++ b/problems/0202.快乐数.md
@@ -215,6 +215,23 @@ var isHappy = function(n) {
}
return n === 1;
};
+
+// 方法四:使用Set(),求和用reduce
+var isHappy = function(n) {
+ let set = new Set();
+ let totalCount;
+ while(totalCount !== 1) {
+ let arr = (''+(totalCount || n)).split('');
+ totalCount = arr.reduce((total, num) => {
+ return total + num * num
+ }, 0)
+ if (set.has(totalCount)) {
+ return false;
+ }
+ set.add(totalCount);
+ }
+ return true;
+};
```
Swift:
From fb7a575c05fe6a70d34a82fbaff9d634472e1e23 Mon Sep 17 00:00:00 2001
From: Arthur
Date: Fri, 22 Oct 2021 16:28:50 +0100
Subject: [PATCH 263/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200344.=E5=8F=8D?=
=?UTF-8?q?=E8=BD=AC=E5=AD=97=E7=AC=A6=E4=B8=B2.md=20C=E8=AF=AD=E8=A8=80?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0344.反转字符串.md | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/problems/0344.反转字符串.md b/problems/0344.反转字符串.md
index a5f18d58..b08c3f21 100644
--- a/problems/0344.反转字符串.md
+++ b/problems/0344.反转字符串.md
@@ -218,7 +218,19 @@ func reverseString(_ s: inout [Character]) {
}
```
+C:
+```c
+void reverseString(char* s, int sSize){
+ int left = 0;
+ int right = sSize - 1;
+ while(left < right) {
+ char temp = s[left];
+ s[left++] = s[right];
+ s[right--] = temp;
+ }
+}
+```
-----------------------
From 344dce02b36b6af546ccbe308c2e599f2b0312f0 Mon Sep 17 00:00:00 2001
From: Junwen Huang
Date: Sat, 23 Oct 2021 10:32:35 +0800
Subject: [PATCH 264/284] =?UTF-8?q?Update=200257.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E7=9A=84=E6=89=80=E6=9C=89=E8=B7=AF=E5=BE=84.md=20?=
=?UTF-8?q?=E2=80=94=E2=80=94=20=E5=A2=9E=E5=8A=A0go=E4=B8=8Ejs=E8=AF=AD?=
=?UTF-8?q?=E8=A8=80=E7=9A=84=E9=80=92=E5=BD=92=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0257.二叉树的所有路径.md | 66 ++++++++++++++++++++++++++++++-
1 file changed, 65 insertions(+), 1 deletion(-)
diff --git a/problems/0257.二叉树的所有路径.md b/problems/0257.二叉树的所有路径.md
index f902aab2..b15fa1be 100644
--- a/problems/0257.二叉树的所有路径.md
+++ b/problems/0257.二叉树的所有路径.md
@@ -469,6 +469,9 @@ class Solution:
---
Go:
+
+递归法:
+
```go
func binaryTreePaths(root *TreeNode) []string {
res := make([]string, 0)
@@ -491,10 +494,45 @@ func binaryTreePaths(root *TreeNode) []string {
return res
}
```
+
+迭代法:
+
+```go
+func binaryTreePaths(root *TreeNode) []string {
+ stack := []*TreeNode{}
+ paths := make([]string, 0)
+ res := make([]string, 0)
+ if root != nil {
+ stack = append(stack, root)
+ paths = append(paths, "")
+ }
+ for len(stack) > 0 {
+ l := len(stack)
+ node := stack[l-1]
+ path := paths[l-1]
+ stack = stack[:l-1]
+ paths = paths[:l-1]
+ if node.Left == nil && node.Right == nil {
+ res = append(res, path+strconv.Itoa(node.Val))
+ continue
+ }
+ if node.Right != nil {
+ stack = append(stack, node.Right)
+ paths = append(paths, path+strconv.Itoa(node.Val)+"->")
+ }
+ if node.Left != nil {
+ stack = append(stack, node.Left)
+ paths = append(paths, path+strconv.Itoa(node.Val)+"->")
+ }
+ }
+ return res
+}
+```
+
---
JavaScript:
-1.递归版本
+递归法:
```javascript
var binaryTreePaths = function(root) {
@@ -518,6 +556,32 @@ var binaryTreePaths = function(root) {
};
```
+迭代法:
+
+```javascript
+var binaryTreePaths = function(root) {
+ if (!root) return [];
+ const stack = [root], paths = [''], res = [];
+ while (stack.length) {
+ const node = stack.pop();
+ let path = paths.pop();
+ if (!node.left && !node.right) { // 到叶子节点终止, 添加路径到结果中
+ res.push(path + node.val);
+ continue;
+ }
+ path += node.val + '->';
+ if (node.right) { // 右节点存在
+ stack.push(node.right);
+ paths.push(path);
+ }
+ if (node.left) { // 左节点存在
+ stack.push(node.left);
+ paths.push(path);
+ }
+ }
+ return res;
+};
+```
From fdca5f00ffd6108b544ff6d647fd88fb7490dd54 Mon Sep 17 00:00:00 2001
From: SambacFeng <56753082+SambacFeng@users.noreply.github.com>
Date: Sat, 23 Oct 2021 16:32:28 +0800
Subject: [PATCH 265/284] =?UTF-8?q?update=200450.=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91=E4=B8=AD=E7=9A=84?=
=?UTF-8?q?=E8=8A=82=E7=82=B9=EF=BC=8C=E5=A2=9E=E5=8A=A0js=E7=9A=84?=
=?UTF-8?q?=E8=BF=AD=E4=BB=A3=E5=86=99=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0450.删除二叉搜索树中的节点.md | 35 +++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/problems/0450.删除二叉搜索树中的节点.md b/problems/0450.删除二叉搜索树中的节点.md
index 32dd862e..23e710ad 100644
--- a/problems/0450.删除二叉搜索树中的节点.md
+++ b/problems/0450.删除二叉搜索树中的节点.md
@@ -485,6 +485,41 @@ var deleteNode = function (root, key) {
};
```
+迭代
+``` javascript
+var deleteNode = function (root, key) {
+ const deleteOneNode = target => {
+ if (!target) return target
+ if (!target.right) return target.left
+ let cur = target.right
+ while (cur.left) {
+ cur = cur.left
+ }
+ cur.left = target.left
+ return target.right
+ }
+
+ if (!root) return root
+ let cur = root
+ let pre = null
+ while (cur) {
+ if (cur.val === key) break
+ pre = cur
+ cur.val > key ? cur = cur.left : cur = cur.right
+ }
+ if (!pre) {
+ return deleteOneNode(cur)
+ }
+ if (pre.left && pre.left.val === key) {
+ pre.left = deleteOneNode(cur)
+ }
+ if (pre.right && pre.right.val === key) {
+ pre.right = deleteOneNode(cur)
+ }
+ return root
+}
+```
+
-----------------------
From 74cb27fa2c8106fbcd6a25344ae474f81078f198 Mon Sep 17 00:00:00 2001
From: Junwen Huang
Date: Sat, 23 Oct 2021 20:47:43 +0800
Subject: [PATCH 266/284] =?UTF-8?q?Update=200106.=E4=BB=8E=E4=B8=AD?=
=?UTF-8?q?=E5=BA=8F=E4=B8=8E=E5=90=8E=E5=BA=8F=E9=81=8D=E5=8E=86=E5=BA=8F?=
=?UTF-8?q?=E5=88=97=E6=9E=84=E9=80=A0=E4=BA=8C=E5=8F=89=E6=A0=91.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
优化js版本代码并添加注释说明
---
.../0106.从中序与后序遍历序列构造二叉树.md | 31 +++++++++----------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/problems/0106.从中序与后序遍历序列构造二叉树.md b/problems/0106.从中序与后序遍历序列构造二叉树.md
index a83341fd..11083a59 100644
--- a/problems/0106.从中序与后序遍历序列构造二叉树.md
+++ b/problems/0106.从中序与后序遍历序列构造二叉树.md
@@ -792,16 +792,13 @@ func findRootIndex(target int,inorder []int) int{
```javascript
var buildTree = function(inorder, postorder) {
- if (!postorder.length) return null
-
- let root = new TreeNode(postorder[postorder.length - 1])
-
- let index = inorder.findIndex(number => number === root.val)
-
- root.left = buildTree(inorder.slice(0, index), postorder.slice(0, index))
- root.right = buildTree(inorder.slice(index + 1, inorder.length), postorder.slice(index, postorder.length - 1))
-
- return root
+ if (!preorder.length) return null;
+ const rootVal = postorder.pop(); // 从后序遍历的数组中获取中间节点的值, 即数组最后一个值
+ let rootIndex = inorder.indexOf(rootVal); // 获取中间节点在中序遍历中的下标
+ const root = new TreeNode(rootVal); // 创建中间节点
+ root.left = buildTree(inorder.slice(0, rootIndex), postorder.slice(0, rootIndex)); // 创建左节点
+ root.right = buildTree(inorder.slice(rootIndex + 1), postorder.slice(rootIndex)); // 创建右节点
+ return root;
};
```
@@ -809,13 +806,13 @@ var buildTree = function(inorder, postorder) {
```javascript
var buildTree = function(preorder, inorder) {
- if(!preorder.length)
- return null;
- let root = new TreeNode(preorder[0]);
- let mid = inorder.findIndex((number) => number === root.val);
- root.left = buildTree(preorder.slice(1, mid + 1), inorder.slice(0, mid));
- root.right = buildTree(preorder.slice(mid + 1, preorder.length), inorder.slice(mid + 1, inorder.length));
- return root;
+ if (!preorder.length) return null;
+ const rootVal = preorder.shift(); // 从前序遍历的数组中获取中间节点的值, 即数组第一个值
+ const index = inorder.indexOf(rootVal); // 获取中间节点在中序遍历中的下标
+ const root = new TreeNode(rootVal); // 创建中间节点
+ root.left = buildTree(preorder.slice(0, index), inorder.slice(0, index)); // 创建左节点
+ root.right = buildTree(preorder.slice(index), inorder.slice(index + 1)); // 创建右节点
+ return root;
};
```
From 90ed55b5da370129f9d50691c7d1985642c2a818 Mon Sep 17 00:00:00 2001
From: hailincai
Date: Sun, 24 Oct 2021 08:01:53 -0400
Subject: [PATCH 267/284] =?UTF-8?q?Update=20=E4=BA=8C=E5=8F=89=E6=A0=91?=
=?UTF-8?q?=E7=9A=84=E9=80=92=E5=BD=92=E9=81=8D=E5=8E=86.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修改错别字
---
problems/二叉树的递归遍历.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/二叉树的递归遍历.md b/problems/二叉树的递归遍历.md
index eee150b7..209cbcb7 100644
--- a/problems/二叉树的递归遍历.md
+++ b/problems/二叉树的递归遍历.md
@@ -54,7 +54,7 @@ traversal(cur->left, vec); // 左
traversal(cur->right, vec); // 右
```
-单层递归的逻辑就是按照中左右的顺序来处理的,这样二叉树的前序遍历,基本就写完了,在看一下完整代码:
+单层递归的逻辑就是按照中左右的顺序来处理的,这样二叉树的前序遍历,基本就写完了,再看一下完整代码:
前序遍历:
From c8cc5b51207e045f594209332009d985545ca52c Mon Sep 17 00:00:00 2001
From: hailincai
Date: Sun, 24 Oct 2021 09:51:56 -0400
Subject: [PATCH 268/284] =?UTF-8?q?Update=200053.=E6=9C=80=E5=A4=A7?=
=?UTF-8?q?=E5=AD=90=E5=BA=8F=E5=92=8C.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
增加dp方法
---
problems/0053.最大子序和.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/problems/0053.最大子序和.md b/problems/0053.最大子序和.md
index 75281210..5c45aa0a 100644
--- a/problems/0053.最大子序和.md
+++ b/problems/0053.最大子序和.md
@@ -161,6 +161,25 @@ class Solution {
}
```
+```java
+// DP 方法
+class Solution {
+ public int maxSubArray(int[] nums) {
+ int ans = Integer.MIN_VALUE;
+ int[] dp = new int[nums.length];
+ dp[0] = nums[0];
+ ans = dp[0];
+
+ for (int i = 1; i < nums.length; i++){
+ dp[i] = Math.max(dp[i-1] + nums[i], nums[i]);
+ ans = Math.max(dp[i], ans);
+ }
+
+ return ans;
+ }
+}
+```
+
Python:
```python
class Solution:
From f9abccf8892f4d7054806a97a84110846e3d047f Mon Sep 17 00:00:00 2001
From: hailincai
Date: Sun, 24 Oct 2021 09:53:42 -0400
Subject: [PATCH 269/284] =?UTF-8?q?Update=200376.=E6=91=86=E5=8A=A8?=
=?UTF-8?q?=E5=BA=8F=E5=88=97.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
增加dp方法
---
problems/0376.摆动序列.md | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md
index 5587a8c7..e58a26ff 100644
--- a/problems/0376.摆动序列.md
+++ b/problems/0376.摆动序列.md
@@ -199,6 +199,36 @@ class Solution {
}
```
+```java
+// DP
+class Solution {
+ public int wiggleMaxLength(int[] nums) {
+ // 0 i 作为波峰的最大长度
+ // 1 i 作为波谷的最大长度
+ int dp[][] = new int[nums.length][2];
+
+ dp[0][0] = dp[0][1] = 1;
+ for (int i = 1; i < nums.length; i++){
+ //i 自己可以成为波峰或者波谷
+ dp[i][0] = dp[i][1] = 1;
+
+ for (int j = 0; j < i; j++){
+ if (nums[j] > nums[i]){
+ // i 是波谷
+ dp[i][1] = Math.max(dp[i][1], dp[j][0] + 1);
+ }
+ if (nums[j] < nums[i]){
+ // i 是波峰
+ dp[i][0] = Math.max(dp[i][0], dp[j][1] + 1);
+ }
+ }
+ }
+
+ return Math.max(dp[nums.length - 1][0], dp[nums.length - 1][1]);
+ }
+}
+```
+
Python:
```python3
class Solution:
From 61838527a072acd7cf7fb4e3fce8de0f4ff91fce Mon Sep 17 00:00:00 2001
From: hailincai
Date: Sun, 24 Oct 2021 10:07:34 -0400
Subject: [PATCH 270/284] =?UTF-8?q?Update=200509.=E6=96=90=E6=B3=A2?=
=?UTF-8?q?=E9=82=A3=E5=A5=91=E6=95=B0.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
增加java非压缩状态版本,易于理解
---
problems/0509.斐波那契数.md | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/problems/0509.斐波那契数.md b/problems/0509.斐波那契数.md
index 4102dd64..cb54a0f9 100644
--- a/problems/0509.斐波那契数.md
+++ b/problems/0509.斐波那契数.md
@@ -186,6 +186,26 @@ class Solution {
}
```
+```java
+//非压缩状态的版本
+class Solution {
+ public int fib(int n) {
+ if (n <= 1) return n;
+
+ int[] dp = new int[n + 1];
+
+ dp[0] = 0;
+ dp[1] = 1;
+
+ for (int index = 2; index <= n; index++){
+ dp[index] = dp[index - 1] + dp[index - 2];
+ }
+
+ return dp[n];
+ }
+}
+```
+
Python:
```python3
class Solution:
From 09e82fa59602210006e8fbc9977119bcd3b3030c Mon Sep 17 00:00:00 2001
From: hailincai
Date: Sun, 24 Oct 2021 10:28:31 -0400
Subject: [PATCH 271/284] =?UTF-8?q?Update=20=E5=93=88=E5=B8=8C=E8=A1=A8?=
=?UTF-8?q?=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fix typo
---
problems/哈希表理论基础.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/哈希表理论基础.md b/problems/哈希表理论基础.md
index aeb11b2e..05fb2a32 100644
--- a/problems/哈希表理论基础.md
+++ b/problems/哈希表理论基础.md
@@ -32,7 +32,7 @@
## 哈希函数
-哈希函数,把学生的姓名直接映射为哈希表上的索引,然后就可以通过查询索引下表快速知道这位同学是否在这所学校里了。
+哈希函数,把学生的姓名直接映射为哈希表上的索引,然后就可以通过查询索引下标快速知道这位同学是否在这所学校里了。
哈希函数如下图所示,通过hashCode把名字转化为数值,一般hashcode是通过特定编码方式,可以将其他数据格式转化为不同的数值,这样就把学生名字映射为哈希表上的索引数字了。
From 825600a1d2c67f34fd9ecae91a171475c1ee1cb7 Mon Sep 17 00:00:00 2001
From: sugarlesss
Date: Mon, 25 Oct 2021 10:38:34 +0800
Subject: [PATCH 272/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E9=9D=A2=E8=AF=95?=
=?UTF-8?q?=E9=A2=9802.07.=E9=93=BE=E8=A1=A8=E7=9B=B8=E4=BA=A4=20=E9=94=99?=
=?UTF-8?q?=E5=88=AB=E5=AD=97=E5=8B=98=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/面试题02.07.链表相交.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/面试题02.07.链表相交.md b/problems/面试题02.07.链表相交.md
index f283b161..c5b8ed6f 100644
--- a/problems/面试题02.07.链表相交.md
+++ b/problems/面试题02.07.链表相交.md
@@ -38,7 +38,7 @@

-此时我们就可以比较curA和curB是否相同,如果不相同,同时向后移动curA和curB,如果遇到curA == curB,则找到焦点。
+此时我们就可以比较curA和curB是否相同,如果不相同,同时向后移动curA和curB,如果遇到curA == curB,则找到交点。
否则循环退出返回空指针。
From 104ba7c7a8ac81bea9b329eb92fc24797ac29588 Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Mon, 25 Oct 2021 12:48:55 +0800
Subject: [PATCH 273/284] Update
---
README.md | 10 +-
problems/0035.搜索插入位置.md | 57 ++---
problems/0037.解数独.md | 21 +-
problems/0046.全排列.md | 22 +-
problems/0047.全排列II.md | 55 +---
problems/0051.N皇后.md | 55 ++--
problems/0090.子集II.md | 25 +-
problems/0093.复原IP地址.md | 3 +-
problems/0110.平衡二叉树.md | 2 +-
problems/0332.重新安排行程.md | 25 +-
problems/0491.递增子序列.md | 23 +-
problems/0724.寻找数组的中心索引.md | 14 +-
problems/0922.按奇偶排序数组II.md | 30 +--
problems/前序/互联网大厂研发流程.md | 238 ++++++++++++++++++
problems/知识星球精选/HR特意刁难非科班.md | 47 ++++
problems/知识星球精选/offer的选择.md | 137 ++++++++++
.../知识星球精选/初入大三选择考研VS工作.md | 49 ++++
problems/知识星球精选/天下乌鸦一般黑.md | 71 ++++++
problems/知识星球精选/非科班2021秋招总结.md | 117 +++++++++
19 files changed, 804 insertions(+), 197 deletions(-)
create mode 100644 problems/前序/互联网大厂研发流程.md
create mode 100644 problems/知识星球精选/HR特意刁难非科班.md
create mode 100644 problems/知识星球精选/offer的选择.md
create mode 100644 problems/知识星球精选/初入大三选择考研VS工作.md
create mode 100644 problems/知识星球精选/天下乌鸦一般黑.md
create mode 100644 problems/知识星球精选/非科班2021秋招总结.md
diff --git a/README.md b/README.md
index 6a64da9f..9e255970 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
> 1. **介绍**:本项目是一套完整的刷题计划,旨在帮助大家少走弯路,循序渐进学算法,[关注作者](#关于作者)
> 2. **PDF版本** : [「代码随想录」算法精讲 PDF 版本](https://mp.weixin.qq.com/s/RsdcQ9umo09R6cfnwXZlrQ) 。
> 3. **刷题顺序** : README已经将刷题顺序排好了,按照顺序一道一道刷就可以。
-> 3. **学习社区** : 一起学习打卡/面试技巧/如何选择offer/大厂内推/职场规则/简历修改/技术分享/程序人生。欢迎加入[「代码随想录」学习社区](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) 。
+> 3. **学习社区** : 一起学习打卡/面试技巧/如何选择offer/大厂内推/职场规则/简历修改/技术分享/程序人生。欢迎加入[「代码随想录」知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) 。
> 4. **提交代码**:本项目统一使用C++语言进行讲解,但已经有Java、Python、Go、JavaScript等等多语言版本,感谢[这里的每一位贡献者](https://github.com/youngyangyang04/leetcode-master/graphs/contributors),如果你也想贡献代码点亮你的头像,[点击这里](https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A)了解提交代码的方式。
> 5. **转载须知** :以下所有文章皆为我([程序员Carl](https://github.com/youngyangyang04))的原创。引用本项目文章请注明出处,发现恶意抄袭或搬运,会动用法律武器维护自己的权益。让我们一起维护一个良好的技术创作环境!
@@ -97,6 +97,8 @@
* [看了这么多代码,谈一谈代码风格!](./problems/前序/代码风格.md)
* [力扣上的代码想在本地编译运行?](./problems/前序/力扣上的代码想在本地编译运行?.md)
* [什么是核心代码模式,什么又是ACM模式?](./problems/前序/什么是核心代码模式,什么又是ACM模式?.md)
+ * [ACM模式如何构造二叉树](./problems/前序/ACM模式如何构建二叉树.md)
+ * [解密互联网大厂研发流程](./problems/前序/互联网大厂研发流程.md)
* 工具
* [一站式vim配置](https://github.com/youngyangyang04/PowerVim)
@@ -124,6 +126,11 @@
## 知识星球精选
+* [HR特意刁难非科班!](./problems/知识星球精选/HR特意刁难非科班.md)
+* [offer的选择](./problems/知识星球精选/offer的选择.md)
+* [天下乌鸦一般黑,哪家没有PUA?](./problems/知识星球精选/天下乌鸦一般黑.md)
+* [初入大三,考研VS工作](./problems/知识星球精选/初入大三选择考研VS工作.md)
+* [非科班2021秋招总结](./problems/知识星球精选/非科班2021秋招总结.md)
* [秋招下半场依然没offer,怎么办?](./problems/知识星球精选/秋招下半场依然没offer.md)
* [合适自己的就是最好的](./problems/知识星球精选/合适自己的就是最好的.md)
* [为什么都说客户端会消失](./problems/知识星球精选/客三消.md)
@@ -466,6 +473,7 @@
* [234.回文链表](./problems/0234.回文链表.md)
* [143.重排链表](./problems/0143.重排链表.md)【数组】【双向队列】【直接操作链表】
* [141.环形链表](./problems/0141.环形链表.md)
+* [160.相交链表](./problems/面试题02.07.链表相交.md)
## 哈希表
* [205.同构字符串](./problems/0205.同构字符串.md):【哈希表的应用】
diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md
index 593e3fe5..58171f59 100644
--- a/problems/0035.搜索插入位置.md
+++ b/problems/0035.搜索插入位置.md
@@ -18,22 +18,22 @@
你可以假设数组中无重复元素。
示例 1:
-输入: [1,3,5,6], 5
-输出: 2
+* 输入: [1,3,5,6], 5
+* 输出: 2
示例 2:
-输入: [1,3,5,6], 2
-输出: 1
+* 输入: [1,3,5,6], 2
+* 输出: 1
示例 3:
-输入: [1,3,5,6], 7
-输出: 4
+* 输入: [1,3,5,6], 7
+* 输出: 4
示例 4:
-输入: [1,3,5,6], 0
-输出: 0
+* 输入: [1,3,5,6], 0
+* 输出: 0
-# 思路
+## 思路
这道题目不难,但是为什么通过率相对来说并不高呢,我理解是大家对边界处理的判断有所失误导致的。
@@ -50,13 +50,13 @@
接下来我将从暴力的解法和二分法来讲解此题,也借此好好讲一讲二分查找法。
-## 暴力解法
+### 暴力解法
暴力解题 不一定时间消耗就非常高,关键看实现的方式,就像是二分查找时间消耗不一定就很低,是一样的。
-## 暴力解法C++代码
+C++代码
-```
+```CPP
class Solution {
public:
int searchInsert(vector& nums, int target) {
@@ -75,14 +75,14 @@ public:
};
```
-时间复杂度:O(n)
-空间复杂度:O(1)
+* 时间复杂度:O(n)
+* 空间复杂度:O(1)
效率如下:

-## 二分法
+### 二分法
既然暴力解法的时间复杂度是O(n),就要尝试一下使用二分查找法。
@@ -108,7 +108,7 @@ public:
要在二分查找的过程中,保持不变量,这也就是**循环不变量** (感兴趣的同学可以查一查)。
-## 二分法第一种写法
+### 二分法第一种写法
以这道题目来举例,以下的代码中定义 target 是在一个在左闭右闭的区间里,**也就是[left, right] (这个很重要)**。
@@ -142,13 +142,13 @@ public:
}
};
```
-时间复杂度:O(logn)
-时间复杂度:O(1)
+* 时间复杂度:O(logn)
+* 时间复杂度:O(1)
效率如下:

-## 二分法第二种写法
+### 二分法第二种写法
如果说定义 target 是在一个在左闭右开的区间里,也就是[left, right) 。
@@ -185,10 +185,10 @@ public:
};
```
-时间复杂度:O(logn)
-时间复杂度:O(1)
+* 时间复杂度:O(logn)
+* 时间复杂度:O(1)
-# 总结
+## 总结
希望通过这道题目,大家会发现平时写二分法,为什么总写不好,就是因为对区间定义不清楚。
@@ -196,16 +196,11 @@ public:
然后在**二分查找的循环中,坚持循环不变量的原则**,很多细节问题,自然会知道如何处理了。
-**循序渐进学算法,认准「代码随想录」,Carl手把手带你过关斩将!**
-
-
-
-
## 其他语言版本
-Java:
+### Java
```java
class Solution {
@@ -234,7 +229,7 @@ class Solution {
```
-Python:
+### Python
```python3
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
@@ -252,7 +247,7 @@ class Solution:
return right + 1
```
-JavaScript:
+### JavaScript
```js
var searchInsert = function (nums, target) {
let l = 0, r = nums.length - 1, ans = nums.length;
@@ -272,7 +267,7 @@ var searchInsert = function (nums, target) {
};
```
-Swift:
+### Swift
```swift
// 暴力法
diff --git a/problems/0037.解数独.md b/problems/0037.解数独.md
index 7bc07252..30c50365 100644
--- a/problems/0037.解数独.md
+++ b/problems/0037.解数独.md
@@ -9,7 +9,7 @@
如果对回溯法理论还不清楚的同学,可以先看这个视频[视频来了!!带你学透回溯算法(理论篇)](https://mp.weixin.qq.com/s/wDd5azGIYWjbU0fdua_qBg)
-## 37. 解数独
+# 37. 解数独
[力扣题目链接](https://leetcode-cn.com/problems/sudoku-solver/)
@@ -53,7 +53,7 @@

-## 回溯三部曲
+### 回溯三部曲
* 递归函数以及参数
@@ -115,7 +115,7 @@ bool backtracking(vector>& board) {
那么会直接返回, **这也就是为什么没有终止条件也不会永远填不满棋盘而无限递归下去!**
-## 判断棋盘是否合法
+### 判断棋盘是否合法
判断棋盘是否合法有如下三个维度:
@@ -150,9 +150,8 @@ bool isValid(int row, int col, char val, vector>& board) {
}
```
-最后整体代码如下:
+最后整体C++代码如下:
-## C++代码
```CPP
class Solution {
@@ -218,7 +217,7 @@ public:
## 其他语言版本
-Java:
+### Java
```java
class Solution {
public void solveSudoku(char[][] board) {
@@ -286,7 +285,7 @@ class Solution {
}
```
-Python:
+### Python
```python3
class Solution:
def solveSudoku(self, board: List[List[str]]) -> None:
@@ -321,7 +320,7 @@ class Solution:
backtrack(board)
```
-Python3:
+### Python3
```python3
class Solution:
@@ -374,7 +373,7 @@ class Solution:
self.isSolved()
```
-Go:
+### Go
```go
func solveSudoku(board [][]byte) {
@@ -431,7 +430,7 @@ func isvalid(row,col int,k byte,board [][]byte)bool{
-Javascript:
+### Javascript
```Javascript
var solveSudoku = function(board) {
function isValid(row, col, val, board) {
@@ -487,7 +486,7 @@ var solveSudoku = function(board) {
};
```
-C:
+### C
```C
bool isValid(char** board, int row, int col, int k) {
diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md
index 487a07ad..bf104acd 100644
--- a/problems/0046.全排列.md
+++ b/problems/0046.全排列.md
@@ -7,15 +7,15 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
-## 46.全排列
+# 46.全排列
[力扣题目链接](https://leetcode-cn.com/problems/permutations/)
给定一个 没有重复 数字的序列,返回其所有可能的全排列。
示例:
-输入: [1,2,3]
-输出:
+* 输入: [1,2,3]
+* 输出:
[
[1,2,3],
[1,3,2],
@@ -42,7 +42,7 @@

-## 回溯三部曲
+### 回溯三部曲
* 递归函数参数
@@ -105,7 +105,6 @@ for (int i = 0; i < nums.size(); i++) {
整体C++代码如下:
-
```CPP
class Solution {
public:
@@ -148,8 +147,8 @@ public:
## 其他语言版本
+### Java
-Java:
```java
class Solution {
@@ -182,7 +181,8 @@ class Solution {
}
}
}
-```
+```
+
```java
// 解法2:通过判断path中是否存在数字,排除已经选择的数字
class Solution {
@@ -210,8 +210,8 @@ class Solution {
}
```
-Python:
-```python3
+### Python
+```python
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
res = [] #存放符合条件结果的集合
@@ -251,7 +251,7 @@ class Solution:
return res
```
-Go:
+### Go
```Go
var res [][]int
func permute(nums []int) [][]int {
@@ -278,7 +278,7 @@ func backTrack(nums []int,numsLen int,path []int) {
```
-Javascript:
+### Javascript
```js
diff --git a/problems/0047.全排列II.md b/problems/0047.全排列II.md
index 4c2c2758..e4aca30c 100644
--- a/problems/0047.全排列II.md
+++ b/problems/0047.全排列II.md
@@ -15,15 +15,15 @@
给定一个可包含重复数字的序列 nums ,按任意顺序 返回所有不重复的全排列。
示例 1:
-输入:nums = [1,1,2]
-输出:
+* 输入:nums = [1,1,2]
+* 输出:
[[1,1,2],
[1,2,1],
[2,1,1]]
示例 2:
-输入:nums = [1,2,3]
-输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
+* 输入:nums = [1,2,3]
+* 输出:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
提示:
* 1 <= nums.length <= 8
@@ -153,7 +153,7 @@ if (i > 0 && nums[i] == nums[i - 1] && used[i - 1] == true) {
## 其他语言版本
-java:
+### java
```java
class Solution {
@@ -195,7 +195,7 @@ class Solution {
}
```
-python:
+### python
```python
class Solution:
@@ -223,7 +223,7 @@ class Solution:
return res
```
-Go:
+### Go
```go
var res [][]int
@@ -256,7 +256,7 @@ func backTrack(nums []int,numsLen int,path []int) {
}
```
-Javascript:
+### Javascript
```javascript
@@ -292,45 +292,6 @@ var permuteUnique = function (nums) {
};
```
-Go:
-回溯+本层去重+下层去重
-```golang
-func permuteUnique(nums []int) [][]int {
- var subRes []int
- var res [][]int
- sort.Ints(nums)
- used:=make([]bool,len(nums))
- backTring(nums,subRes,&res,used)
- return res
-}
-func backTring(nums,subRes []int,res *[][]int,used []bool){
- if len(subRes)==len(nums){
- tmp:=make([]int,len(nums))
- copy(tmp,subRes)
- *res=append(*res,tmp)
- return
- }
- // used[i - 1] == true,说明同一树支candidates[i - 1]使用过
- // used[i - 1] == false,说明同一树层candidates[i - 1]使用过
- for i:=0;i0&&nums[i]==nums[i-1]&&used[i-1]==false{//当本层元素相同且前一个被使用过,则继续向后找(本层去重)
- continue
- }
- //到达这里有两种情况:1.该层前后元素不同;2.该层前后元素相同但该层没有使用过
- //所以只能对该层没有被使用过的抽取
- if used[i]==false{
- //首先将该元素置为使用过(即同一树枝使用过),下一层的元素就不能选择重复使用过的元素(下层去重)
- used[i]=true
- subRes=append(subRes,nums[i])
- backTring(nums,subRes,res,used)
- //回溯
- //回溯回来,将该元素置为false,表示该元素在该层使用过
- used[i]=false
- subRes=subRes[:len(subRes)-1]
- }
- }
-}
-```
diff --git a/problems/0051.N皇后.md b/problems/0051.N皇后.md
index 7e2b202f..71f04097 100644
--- a/problems/0051.N皇后.md
+++ b/problems/0051.N皇后.md
@@ -7,46 +7,28 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
-## 第51题. N皇后
+# 第51题. N皇后
[力扣题目链接](https://leetcode-cn.com/problems/n-queens/)
-n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
+n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
-上图为 8 皇后问题的一种解法。
-
+给你一个整数 n ,返回所有不同的 n 皇后问题 的解决方案。
-给定一个整数 n,返回所有不同的 n 皇后问题的解决方案。
+每一种解法包含一个不同的 n 皇后问题 的棋子放置方案,该方案中 'Q' 和 '.' 分别代表了皇后和空位。
-每一种解法包含一个明确的 n 皇后问题的棋子放置方案,该方案中 'Q' 和 '.' 分别代表了皇后和空位。
+示例 1:
-示例:
+
-输入: 4
+* 输入:n = 4
+* 输出:[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
+* 解释:如上图所示,4 皇后问题存在两个不同的解法。
-输出:
-
-解法 1
-
-[
- [".Q..",
- "...Q",
- "Q...",
- "..Q."],
-
-解法 2
-
- ["..Q.",
- "Q...",
- "...Q",
- ".Q.."]
-]
-
-解释: 4 皇后问题存在两个不同的解法。
-
-提示:
-> 皇后,是国际象棋中的棋子,意味着国王的妻子。皇后只做一件事,那就是“吃子”。当她遇见可以吃的棋子时,就迅速冲上去吃掉棋子。当然,她横、竖、斜都可走一到七步,可进可退。(引用自 百度百科 - 皇后 )
+示例 2:
+* 输入:n = 1
+* 输出:[["Q"]]
## 思路
@@ -71,7 +53,7 @@ n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并
那么我们用皇后们的约束条件,来回溯搜索这颗树,**只要搜索到了树的叶子节点,说明就找到了皇后们的合理位置了**。
-## 回溯三部曲
+### 回溯三部曲
按照我总结的如下回溯模板,我们来依次分析:
@@ -178,8 +160,6 @@ bool isValid(int row, int col, vector& chessboard, int n) {
那么按照这个模板不难写出如下C++代码:
-## C++代码
-
```CPP
class Solution {
private:
@@ -247,7 +227,7 @@ public:
## 其他语言补充
-Python:
+### Python
```python
class Solution:
@@ -296,7 +276,7 @@ class Solution:
return res
```
-Java:
+### Java
```java
class Solution {
@@ -366,7 +346,7 @@ class Solution {
```
-Go:
+### Go
```Go
import "strings"
var res [][]string
@@ -433,8 +413,7 @@ func solveNQueens(n int) [][]string {
return res
}
```
-
-Javascript:
+### Javascript
```Javascript
var solveNQueens = function(n) {
function isValid(row, col, chessBoard, n) {
diff --git a/problems/0090.子集II.md b/problems/0090.子集II.md
index 7ae7c6c2..2777bc84 100644
--- a/problems/0090.子集II.md
+++ b/problems/0090.子集II.md
@@ -6,8 +6,9 @@
欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
+# 子集问题(二)
-## 第90题.子集II
+## 90.子集II
[力扣题目链接](https://leetcode-cn.com/problems/subsets-ii/)
@@ -16,8 +17,8 @@
说明:解集不能包含重复的子集。
示例:
-输入: [1,2,2]
-输出:
+* 输入: [1,2,2]
+* 输出:
[
[2],
[1],
@@ -46,7 +47,7 @@
本题就是其实就是[回溯算法:求子集问题!](https://programmercarl.com/0078.子集.html)的基础上加上了去重,去重我们在[回溯算法:求组合总和(三)](https://programmercarl.com/0040.组合总和II.html)也讲过了,所以我就直接给出代码了:
-## C++代码
+C++代码如下:
```CPP
class Solution {
@@ -168,7 +169,8 @@ if (i > startIndex && nums[i] == nums[i - 1] ) {
## 其他语言版本
-Java:
+### Java
+
```java
class Solution {
List> result = new ArrayList<>();// 存放符合条件结果的集合
@@ -204,8 +206,8 @@ class Solution {
}
```
-Python:
-```python3
+### Python
+```python
class Solution:
def subsetsWithDup(self, nums: List[int]) -> List[List[int]]:
res = [] #存放符合条件结果的集合
@@ -223,7 +225,8 @@ class Solution:
return res
```
-Go:
+### Go
+
```Go
var res[][]int
func subsetsWithDup(nums []int)[][]int {
@@ -249,7 +252,7 @@ func dfs(temp, num []int, start int) {
```
-Javascript:
+### Javascript
```Javascript
@@ -279,7 +282,8 @@ var subsetsWithDup = function(nums) {
```
-C:
+### C
+
```c
int* path;
int pathTop;
@@ -348,7 +352,6 @@ int** subsetsWithDup(int* nums, int numsSize, int* returnSize, int** returnColum
```
-
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
diff --git a/problems/0093.复原IP地址.md b/problems/0093.复原IP地址.md
index 4e56ddc4..c8e94bf4 100644
--- a/problems/0093.复原IP地址.md
+++ b/problems/0093.复原IP地址.md
@@ -352,6 +352,7 @@ class Solution(object):
ans = []
path = []
def backtrack(path, startIndex):
+ if len(s) > 12: return []
if len(path) == 4:
if startIndex == len(s):
ans.append(".".join(path[:]))
@@ -367,7 +368,7 @@ class Solution(object):
path.pop()
backtrack([], 0)
- return ans```
+ return ans
```
diff --git a/problems/0110.平衡二叉树.md b/problems/0110.平衡二叉树.md
index 7858fa60..40486d38 100644
--- a/problems/0110.平衡二叉树.md
+++ b/problems/0110.平衡二叉树.md
@@ -80,7 +80,7 @@ public:
}
int maxDepth(TreeNode* root) {
result = 0;
- if (root == 0) return result;
+ if (root == NULL) return result;
getDepth(root, 1);
return result;
}
diff --git a/problems/0332.重新安排行程.md b/problems/0332.重新安排行程.md
index 9a9cada9..d3047e94 100644
--- a/problems/0332.重新安排行程.md
+++ b/problems/0332.重新安排行程.md
@@ -9,7 +9,7 @@
> 这也可以用回溯法? 其实深搜和回溯也是相辅相成的,毕竟都用递归。
-## 332.重新安排行程
+# 332.重新安排行程
[力扣题目链接](https://leetcode-cn.com/problems/reconstruct-itinerary/)
@@ -23,13 +23,13 @@
示例 1:
-输入:[["MUC", "LHR"], ["JFK", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]]
-输出:["JFK", "MUC", "LHR", "SFO", "SJC"]
+* 输入:[["MUC", "LHR"], ["JFK", "MUC"], ["SFO", "SJC"], ["LHR", "SFO"]]
+* 输出:["JFK", "MUC", "LHR", "SFO", "SJC"]
示例 2:
-输入:[["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
-输出:["JFK","ATL","JFK","SFO","ATL","SFO"]
-解释:另一种有效的行程是 ["JFK","SFO","ATL","JFK","ATL","SFO"]。但是它自然排序更大更靠后。
+* 输入:[["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
+* 输出:["JFK","ATL","JFK","SFO","ATL","SFO"]
+* 解释:另一种有效的行程是 ["JFK","SFO","ATL","JFK","ATL","SFO"]。但是它自然排序更大更靠后。
## 思路
@@ -75,8 +75,9 @@
含义如下:
-`unordered_map> targets`:`unordered_map<出发机场, 到达机场的集合> targets`
-`unordered_map> targets`:`unordered_map<出发机场, map<到达机场, 航班次数>> targets`
+unordered_map> targets:unordered_map<出发机场, 到达机场的集合> targets
+
+unordered_map> targets:unordered_map<出发机场, map<到达机场, 航班次数>> targets
这两个结构,我选择了后者,因为如果使用`unordered_map> targets` 遍历multiset的时候,不能删除元素,一旦删除元素,迭代器就失效了。
@@ -258,7 +259,7 @@ for (pairtarget : targets[result[result.size() - 1]])
## 其他语言版本
-java 版本:
+### java
```java
class Solution {
@@ -307,7 +308,7 @@ class Solution {
}
```
-python:
+### python
```python
class Solution:
@@ -340,7 +341,7 @@ class Solution:
return path
```
-C语言版本:
+### C语言
```C
char **result;
@@ -402,7 +403,7 @@ char ** findItinerary(char *** tickets, int ticketsSize, int* ticketsColSize, in
}
```
-Javascript:
+### Javascript
```Javascript
var findItinerary = function(tickets) {
diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md
index e947b2b9..e55263a1 100644
--- a/problems/0491.递增子序列.md
+++ b/problems/0491.递增子序列.md
@@ -9,7 +9,7 @@
> 和子集问题有点像,但又处处是陷阱
-## 491.递增子序列
+# 491.递增子序列
[力扣题目链接](https://leetcode-cn.com/problems/increasing-subsequences/)
@@ -17,8 +17,8 @@
示例:
-输入: [4, 6, 7, 7]
-输出: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
+* 输入: [4, 6, 7, 7]
+* 输出: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
说明:
* 给定数组的长度不会超过15。
@@ -50,7 +50,7 @@

-## 回溯三部曲
+### 回溯三部曲
* 递归函数参数
@@ -187,7 +187,6 @@ public:
**所以正如在[哈希表:总结篇!(每逢总结必经典)](https://programmercarl.com/哈希表总结.html)中说的那样,数组,set,map都可以做哈希表,而且数组干的活,map和set都能干,但如果数值范围小的话能用数组尽量用数组**。
-
## 总结
本题题解清一色都说是深度优先搜索,但我更倾向于说它用回溯法,而且本题我也是完全使用回溯法的逻辑来分析的。
@@ -202,7 +201,8 @@ public:
## 其他语言版本
-Java:
+### Java
+
```java
class Solution {
private List path = new ArrayList<>();
@@ -231,8 +231,9 @@ class Solution {
```
-Python:
-```python3
+### Python
+
+```python
class Solution:
def findSubsequences(self, nums: List[int]) -> List[List[int]]:
res = []
@@ -255,7 +256,7 @@ class Solution:
return res
```
-Go:
+### Go
```golang
func findSubsequences(nums []int) [][]int {
@@ -285,7 +286,7 @@ func backTring(startIndex int,nums,subRes []int,res *[][]int){
}
```
-Javascript:
+### Javascript
```Javascript
@@ -313,7 +314,7 @@ var findSubsequences = function(nums) {
```
-C:
+### C
```c
int* path;
int pathTop;
diff --git a/problems/0724.寻找数组的中心索引.md b/problems/0724.寻找数组的中心索引.md
index 13d2ab68..d05d55b8 100644
--- a/problems/0724.寻找数组的中心索引.md
+++ b/problems/0724.寻找数组的中心索引.md
@@ -35,9 +35,9 @@
* 解释:中心下标是 0。左侧数之和 sum = 0 ,(下标 0 左侧不存在元素),右侧数之和 sum = nums[1] + nums[2] = 1 + -1 = 0 。
-# 思路
+## 思路
-这道题目还是比较简单直接啊哈哈
+这道题目还是比较简单直接的
1. 遍历一遍求出总和sum
2. 遍历第二遍求中心索引左半和leftSum
@@ -64,9 +64,9 @@ public:
```
-# 其他语言版本
+## 其他语言版本
-## Java
+### Java
```java
class Solution {
@@ -89,7 +89,7 @@ class Solution {
}
```
-## Python3
+### Python3
```python
class Solution:
@@ -103,7 +103,7 @@ class Solution:
return -1
```
-## Go
+### Go
```go
func pivotIndex(nums []int) int {
@@ -126,7 +126,7 @@ func pivotIndex(nums []int) int {
```
-## JavaScript
+### JavaScript
```js
var pivotIndex = function(nums) {
diff --git a/problems/0922.按奇偶排序数组II.md b/problems/0922.按奇偶排序数组II.md
index 43046133..4f60666f 100644
--- a/problems/0922.按奇偶排序数组II.md
+++ b/problems/0922.按奇偶排序数组II.md
@@ -26,11 +26,11 @@
* 解释:[4,7,2,5],[2,5,4,7],[2,7,4,5] 也会被接受。
-# 思路
+## 思路
这道题目直接的想法可能是两层for循环再加上used数组表示使用过的元素。这样的的时间复杂度是O(n^2)。
-## 方法一
+### 方法一
其实这道题可以用很朴实的方法,时间复杂度就就是O(n)了,C++代码如下:
@@ -59,10 +59,10 @@ public:
};
```
-时间复杂度:O(n)
-空间复杂度:O(n)
+* 时间复杂度:O(n)
+* 空间复杂度:O(n)
-## 方法二
+### 方法二
以上代码我是建了两个辅助数组,而且A数组还相当于遍历了两次,用辅助数组的好处就是思路清晰,优化一下就是不用这两个辅助树,代码如下:
@@ -88,10 +88,10 @@ public:
};
```
-时间复杂度O(n)
-空间复杂度O(n)
+* 时间复杂度O(n)
+* 空间复杂度O(n)
-## 方法三
+### 方法三
当然还可以在原数组上修改,连result数组都不用了。
@@ -111,15 +111,15 @@ public:
};
```
-时间复杂度:O(n)
-空间复杂度:O(1)
+* 时间复杂度:O(n)
+* 空间复杂度:O(1)
这里时间复杂度并不是O(n^2),因为偶数位和奇数位都只操作一次,不是n/2 * n/2的关系,而是n/2 + n/2的关系!
-# 其他语言版本
+## 其他语言版本
-## Java
+### Java
```java
// 方法一
@@ -149,7 +149,7 @@ class Solution {
}
```
-## Python3
+### Python3
```python
#方法2
@@ -179,7 +179,7 @@ class Solution:
return nums
```
-## Go
+### Go
```go
@@ -206,7 +206,7 @@ func sortArrayByParityII(nums []int) []int {
}
```
-## JavaScript
+### JavaScript
```js
//方法一
diff --git a/problems/前序/互联网大厂研发流程.md b/problems/前序/互联网大厂研发流程.md
new file mode 100644
index 00000000..9616958d
--- /dev/null
+++ b/problems/前序/互联网大厂研发流程.md
@@ -0,0 +1,238 @@
+# 揭秘互联网大厂研发流程
+
+很多录友会很好奇这么个事:
+
+* 大厂的研发流程应该是什么样的呢
+* 为什么会有那么多繁琐的流程呢
+* 每一步都有什么作用呢
+
+这次给大家介绍一波大厂的研发流程,让大家明明白白。
+
+同时我已经录制了视频,昨晚已经在B站首发了。
+
+视频里讲的更清楚一点,因为我是没有草稿,先录的视频,然后在根据视频写的文章,写文章的时候,发现我视频里讲的太多了,码字实在是码不过来,所以这篇文字稿中每一个研发环节的解释稍稍精简了一下。
+
+如果详细了解研发流程就直接看视频吧,**别告诉卡哥,你还没关注 「代码随想录」的B站,还不赶紧关注一波[机智]**。
+
+重要重要重要: **要给三连呀!**
+
+[B站:揭秘互联网大厂研发流程](https://www.bilibili.com/video/BV1KR4y1H7ST)
+
+
+其实对于几十人或者上百人一起开发一个项目的话,一个规范的研发流程是很重要的。
+
+有的同学可能想,哪有这么多流程啊,就是写完代码,跑一下,没问题,然后就上线了。
+
+其实在大厂里研发流程是很重要的。
+
+**一个项目从开发到上线到后面的维护,从流程上就保证大家少出错,也方便后面人继续维护**。
+
+那么接下来给大家介绍一下详细的流程。
+
+## 1.需求文档
+
+看需求文档,我们要根据需求文档来确定我们究竟要做什么。
+
+一些同学可能感觉 为什么还要用一个需求文档呢,你就告诉我做啥我就做啥不就完事了。
+
+其实需求文档一方面是倒逼产品经理去系统性的思考这个需求究竟有哪些功能,用来满足哪些用户的需求。
+
+另一方面,是保证我们在研发的时候,研发出来的功能是满足需求文档里所描述的。
+
+如果是口头对接的话,很有可能就是你做出来的东西,产品经理看完感觉:这和我说的需求不一样啊!!这和我想的不一样啊!!
+
+这样就是两个人相互甩锅,那这究竟是谁的锅呢。都没有一个证据,对吧。
+
+所以说,有一个需求文档很重要。
+
+而且每个阶段的需求文档相当于是把这个项目的整个迭代过程都记录下来了。
+
+这样也方便后面的人,了解这个项目是如何迭代的。
+
+## 2.这个需求包含了哪些功能
+
+产品经理在需求文档里描述一个功能,那么我们在实现的时候,可能要改很多模块,或者说我们要增加一些模块。
+
+就是我们从代码的角度上来讲,可能要增添很多功能才能满足 用户看起来好像微不足道的小功能。
+
+例如点击登录,点击下单,后台都有很多模块协同运行的。
+
+我们要把产品经理角度上的这个功能,拆解为我们代码角度上的具体应该开发的那些功能。
+
+## 3.确定有哪些难点
+
+这里可能有同学疑惑了,我确定这东西干嘛呢。
+
+给大家举一个例子,给你一个需求文档。
+
+你说你一周的时间就能把它开发完,那为什么是一周呢,为什么不是两天,为什么不是两周呢。
+
+其实 和上面的领导汇报你的工作的时候 都要把自己的工作进行量化。
+
+那么这个功能有哪些难点,我们要克服这个难点,所需要花费的时间,都要有一个大体的量化。
+
+这样才能量化我们自己的工作,**领导其实不知道你的工作是简单 还是困难, 领导只在意最终结果**,所以你要展现给领导你的工作是有难度的是有挑战的。
+
+而且这些也是我们年底用来晋升或者评职称的素材。
+
+如果这些东西你自己都不在乎的话,谁还会帮你在乎呢。
+
+而且**确定了自己的工作难点,把这些难点都记录下来,对以后跳槽也很有帮助**。
+
+面试官最喜欢问的问题,就是:**你做的项目中有哪些难点?以及你是如何克服的**。
+
+所以这一步对自己个人成长来说也是很有重要的。 对于项目组来说也是记录下来,每一个迭代版本有哪些难点,这些难点团队是如何克服的。
+
+这也是项目组往上一级去邀功的资料。
+
+
+## 4.画架构图
+
+一般来说,大厂项目的架构都是比较复杂的,特别是后端架构。
+
+如果添加一个模块连个文档都没有,连个图也没有,上来就添加的话,后面的人是很难维护的。
+
+而且每个模块和每一个模块之间的依赖关系,如果没有画出一个架构图的话,直接看代码很容易直接就看懵了。
+
+为什么你可以快速开发一个新的模块,也是因为之前团队有人把这个架构图画清楚了,你只需要看一眼这个架构图,就知道你的模块应该添加在哪里。
+
+那么你去添加模块的时候,也应该把这个架构图相应的位置 完善一下。
+
+同时呢,在画架构图的过程中,也增添了自己对整个系统架构的掌握程度。
+
+这个图也会让你确定,你的模块在整个项目中扮演一个什么样的角色。
+
+## 5.定协议
+
+后台模块之间进行通讯需要协议,后台和前端通讯也需要协议。
+
+所以只要有交互,就要确定协议的数据格式。
+
+定协议要考虑到兼容,要考虑易于维护。
+
+## 6.设计数据结构和算法
+
+其实设计数据结构更多一些,因为我们要选择使用什么容器,什么格式来处理我们的数据。
+
+至于算法的话,就很少我们亲自设计了。
+
+什么快排,二叉树,动态规划,最短路啥的,在实际开发中,都不需要我们自己去写,**直接调包!**
+
+面试造火箭,工作拧螺丝 就体现在这里。
+
+为什么会这样呢? 一个很简单的例子,互联网研发讲究其实就是要快,例如一个功能2天就要开发完,如果算法都要自己去写的话,等都写完了,花都谢了。
+
+## 7.预估一下容量
+
+特别是后端开发,要估计出 我们自己模块大体需要多大磁盘,多大内存,多大带宽,多少核CPU。
+
+这也是没有做过研发工作的同学经常忽略的,**因为大家好像默认 磁盘、内存、带宽、cpu是无穷的**。
+
+其实我们在设计一个模块的时候,这些都要评估的,不能模块一上线,把机器直接打爆了,例如 直接把带宽打满了,不仅影响自己的模块功能,还影响了机器上其他模块的运行。
+
+
+## 8.考虑部署
+
+要考虑如果一台机器挂了(可能是硬件原因),那么我们的模块还能不能正常提供服务。
+
+这就是考虑模块的容灾性,一般都是采用分布式,服务部署在三台机器上,一台如果挂了,还有其他两台提供服务。
+
+还有就是要弹性可伸缩,即我们的模块可不可以直接 部署多台机器来提高承载能力。
+
+如果用户量突然上来了,或者流量突然上来了,可以通过快速部署多台机器来抗住流量。而不是模块只能在单机上跑,多部署几台就发生各种问题。
+
+**这才能说明是有足够强的风险意识的**。
+
+## 9.设计评审
+
+前八的阶段其实都是设计阶段,那么你的设计需要让组里的同学一起来评审一下,看看有没有什么问题。
+
+大家主要也是看看你的模块 会不会给其他模块或者整个系统带来什么问题 以及 设计的是否合理。
+
+
+## 10.写代码
+
+终于到写代码的阶段了,其实到这时候,是最容易的。
+
+**写代码就是体力活了,不是脑力活了**。
+
+## 11.自测
+
+写完代码,我们需要自测,自己的功能会不会有什么问题。
+
+这里可能需要自己造一造数据,跑一跑 看看和预想的是不是一样的。
+
+## 12.联调
+
+自己的模块可能会涉及到其他模块之间的一个交互,或者和前端的一个交互。
+
+所以需要其他同学配合一起来测试。
+
+这里就有很多沟通工作了,因为其他同学可能手头有自己的活,那么就要协调一个时间来一起测试。
+
+这一步也是很费时间的,其费时关键是要等,要等其他同学有空和你联调,而且往往不是联调一次就能解决问题的。
+
+所以 在评估开发时间的时候 也要考虑到联调的时间。
+
+这也是大厂研发效率低的地方,但上百人开发的项目,这种沟通上消耗也是在所难免的。
+
+## 13.交给测试
+
+自己的代码,自己测 一般都测不出什么问题,需要交给测试同学来给你测一测。
+
+这里如果测试同学测出问题,你就要判断确实有问题还是 测试方式不对,如果有问题就要修改,在提给测试,反反复复这么几轮,直到测试同学测试没问题了。
+
+这个过程也是累心的。
+
+## 14.code review
+
+代码合入主干之前,需要 项目组的同学一起来评审一下你的代码。
+
+之前是评审设计,看设计上有没有什么缺失,这次是大家来看看你代码写的怎么样。
+
+例如合入主干会不会有什么问题,代码兼容性做的好不好,接口设计的好不好,甚至字段,函数,变量名,命名合不合理。
+
+都要经过大家的评审,如果有问题就还是要改。
+
+如果没有问题一般 大家会给+2(就是通过的意思),这样就可以合入主干了。
+
+## 15.合入主干
+
+合入主干为什么会单独列出来呢。
+
+其实合入主干是很重要的,经常是自己的代码没问题,但合入主干之后就有问题了。
+
+一般就是合入主干的时候有冲突,例如你从主干拉出一个分支,另一个同学从主干拉出一个分支,而且两个分支修改了同一个模块,如果另一个同学提前合入主干,你在合入主干的时候就会有代码冲突。
+
+在解决代码冲突的时候 就会修改别人的代码,这个过程很容易产生新的bug。
+
+**一般合入主干之后,测试同学还要重新跑一个全量测试,才能放心发布**。
+
+## 16.发布
+
+最后一步就是发布了。
+
+发布其实就是把主干的代码更新到线上的服务器上。
+
+一些还没有工作的同学,可能不太理解究竟什么是发布。
+
+用大白话来讲,就是把 本地的代码或者某台机器的代码,编译成可执行文件,然后更新到 线上的服务器(一个独立的集群,专门处理线上的流量)并运行起来。
+
+上线是最重要的一步了,也很容易出问题,因为一个大型项目,其上线的过程都非常复杂(要更新上百台机器的集群),而且要考虑线上新版和旧版本的兼容问题。
+
+这也是为什么大厂项目都选择深夜上线,**因为深夜在线用户最少,如果出问题,影响的用户会比较少,可以快速修复**。
+
+所以大家经常看到 某大厂程序员深夜上线发布版本之类的。
+
+# 总结
+
+好了,整整讲了十六个步骤!把大厂研发流程中 具体都有哪一步,为什么要这么做,都分析的很清楚了。
+
+不过在大厂也不是所有部门都按照这个流程来的,每个部门都有自己玩法,各个部门也不太统一。
+
+我这里是介绍的是已经比较规范的流程,**但流程越正规,研发效率就越低,想要提高效率,就是简化流程,简化流程,就会提高项目出错的概率**。
+
+**所以这也是一个相互权衡的过程,每一个部门可能根据自己的业务特点,适当简化流程**。
+
+好了,讲了这么多,希望对录友们有所启发。
+
diff --git a/problems/知识星球精选/HR特意刁难非科班.md b/problems/知识星球精选/HR特意刁难非科班.md
new file mode 100644
index 00000000..c59debf2
--- /dev/null
+++ b/problems/知识星球精选/HR特意刁难非科班.md
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+# HR特意刁难非科班!
+
+不少录友都是非科班转程序员,或者进军互联网的,但有一些HR在HR面的时候特意刁难大家。
+
+正如[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里,这位录友所遭受的情景。
+
+
+
+1. 你的研究方向并不是这个方面的,你为什么要转行?
+2. 你和非科班的同学相比肯定有一些劣势,你打算怎么赶上他们?或者是你如何应对你作为非科班生在工作中的挑战?
+
+以下是我的回答:
+
+对于问题一,你这么说没问题,可以再润色一下,说一说自己看过哪些技术大牛的传记,例如《黑客与画家》,对自己影响很大,然后对编程就非常感兴趣,想从事这个行业 等等。 或者说 你感觉 新能源汽车是以后非常明确的方向,而自动驾驶是新能源汽车的标配,所以想投身这个行业。
+
+问题二: 首先要自信起来,说:在技术方面和对编程的热情方面,我不比科班同学差,因为大学里教的内容和企业要求的基本脱钩的,大家准备面试进大厂都是靠自学,**反而因为我是非科班,我更加的努力,也特别珍惜来之不易的机会**。
+
+如果要说科班同学有什么优势的话,我感觉他们的学习编程的氛围会好好一些,也就是遇到问题大家能一起交流,因为我车辆工程专业,所以我会经常去蹭计算机的课,也会去认识很多计算机专业的同学和他们一起讨论问题。
+
+总之在HR面的时候,不要说自己哪里的缺点,也不说自己哪里技术掌握的不好,**HR不懂技术,你说自己哪里不懂,他就真认为你不懂了**。
+
+缺点就说一些不痛不痒的,甚至化缺点为自己的优势。
+
+例如问你的缺点是什么?
+
+**可以说自己有时候 对技术细节过于执着,以至于影响整体的进度**。
+
+这种缺点 无形之中 就体现出自己 对技术的热爱和专研 (起到装逼于无形的效果),而且 这种缺点 是分分钟就可以改的。
+
+如果问你 :作为非科班生在工作中的挑战?
+
+你也这么说:其实大家都是靠自学,如果说非科班在工作中遇到的挑战,我相信 科班同学在工作中也是遇到一样的挑战,工作之后自学能力更加重要,互联网变化是飞快的,只有自学能力强的同学才能跟上步伐。
+
+然后随便举例一下,说明自己自学能力如何如何的强,就可以了。
+
+**总之不能示弱,不能说自己哪里不好,哪里不行!**
+
+HR也不懂技术,主要就是看你的态度。
+
+就酱,希望对录友们有所启发,加油💪
+
diff --git a/problems/知识星球精选/offer的选择.md b/problems/知识星球精选/offer的选择.md
new file mode 100644
index 00000000..b9b40dea
--- /dev/null
+++ b/problems/知识星球精选/offer的选择.md
@@ -0,0 +1,137 @@
+
+
+
+
+
+
+# offer的选择
+
+秋招基本要结束了,一些录友也拿到了一些offer,如果是拿到大厂和小厂的offer,那当然就不用纠结了,直接选大厂。
+
+不过大部分同学应该拿到的是 两个大厂offer,或者说拿到两个小厂offer,还要考虑岗位,业务,公司前景,那么就要纠结如何选择了。
+
+在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里,我已经给很多录友提供了选择offer的建议,这里也分享出来,希望对大家在选择offer上有所启发。
+
+## 保研与工作
+
+
+
+1. 建议你直接工作,你都已经拿到了大厂offer,没有必要读研究生了,如果你是保研到 985高校,倒是可以考虑考虑。
+2. 这是送分题,去百度吧,贴吧不算边缘,而且百度对新人的培养体系是很到位了,及时是边缘,对你技术成长也很有帮助,而且还有大厂光环。
+
+3. 星球里 前端同学也很多啊,只不过你没注意到而已,我经常看到。而且前端和后端都是一样的,不能说没地位,不过不同的部门不太一样而已。(大家都是打工的,不用搞出鄙视链哈哈)
+4. 躺平吧,可以歇息了,给还没拿offer的录友一条出路
+
+
+## 阿里云与微众
+
+
+
+中间件一点都不吭啊。
+
+有云的地方,有分布式的地方,就有中间件,应用面很广泛,各大厂哪个能离开云计算,哪个能离开分布式,你就知道中间件有多重要了。当然中间件也是很大的一个领域了,是基础架构范畴。
+
+关于业务部门和基础架构部门的选择,**我也倾向于 应届生选择基础架构部, 业务部门很忙没有时间沉底技术**。
+
+其实你还要考虑,以后跳槽出来如何,在微众做基础架构,以后 跳槽可能更容易一些。注意跳槽不一定是你主动的,可能是被动跳槽。
+
+假如阿里给你来个3.25 你就要找下家了,做 供应链管理 技术上没有太精进的话,找下家不太容易。
+
+关于两个公司,我感觉差不多,微众也很不错,一般给出的薪资都比较高。
+
+至于买房,杭州现在的房价涨的很猛,虽然说整体没有深圳高,但也差不多了,码农聚集地,就别想着房价多便宜。
+
+互联网金融 这块后面发展一定是大势所趋的,不会差。
+
+两个offer都不错,选哪个都可以!
+
+对技术有追求,我倾向于微众,如果对BAT有执念,就去阿里吧。 都差不多。
+
+## 深信服、小米和海康
+
+
+音视频开发现在很火,是一个很好的方向,音视频里也是一个很大的方向了,里面有 音视频信号分析与处理、音视频编解码格式压缩、音视频文件打包封装、流媒体推流协议处理等等。
+
+现在 腾讯会议,阿里钉钉,zoom都是靠音视频技术起家。 而且发展势头很不错。
+
+但如果只是基于现有音视频做 SDK开发,那就没啥意思了。所以也是看具体的工作内容了。
+
+股票这个 不用报太大期望,大概率 你等不到那个时候。
+
+其实 深信服的技术栈 也挺封闭的,毕竟是算是比较偏硬的厂商,深信服做云计算,也是私有云,最终也是卖硬件。
+
+不过小米其实你也说不好最终入职具体是干啥。
+
+选一个的话,倾向于选深信服吧,毕竟深信服总部就在深圳,同事多,大家有个交流,相对来说发展稳定一些。小米 好像最近 深圳才有部门吧,估计应该没多少人,甚至入职之后 可能你单兵作战,和同事没有交流的话,无论是工作还是成长都比较难。
+
+海康更硬一些,是做安防的,所以C++服务器开发基本是服务安防设备。 相对来说,选深信服更好一些,毕竟深信服是做网络安全和云计算的。
+
+## 奇安信、顺网科技和东方财富
+
+
+
+这两家公司我也不太了解。 我就从业务上 简单分析一下
+
+现在很多公司做私有云都有用OpenStack,你针对OpenStack 做二次开发,估计不太用深入理解OpenStack,但如何你能沉下心来学下去,以后跳槽的话 出路还是比较多的。 **就要看你对技术有没有钻劲了**。
+
+东方财富 毕竟不是互联网公司,**主要业务也不是技术驱动,可能技术部门话语权还是挺低的**,大概率 可能是日常后台增删改查处理一些信息,(注意这也是我猜的,真实情况也要亲自体验了才知道)
+
+综上,我感觉 如果对技术热情一般,可以考虑东方财富(毕竟给的钱多), 如果想以后技术立身,考虑奇安信。
+
+
+## 字节客户端、度小满后端
+
+
+你这拿到这么多大厂offer,还说自己菜,凡尔赛石锤了,哈哈哈
+
+客户端确实在劝退,但 客户端不会消失,现在客户端都在往大前端方向去转,**如果你很喜欢字节,喜欢 抖音的话,可以考虑去抖音做IOS**。但如果你一直做IOS的话,指定是发展不容乐观,入职之后就要考虑自己的下一步方向。
+
+度小满后端支付业务 这个其实也不错,支付业务是核心部门,以后跳 微信支付,跳蚂蚁 都是可以的,每个互联网巨头都要做自己的支付。
+
+这两个offer都可以。
+
+如果非要选一个的话,我倾向于 选度小满后端支付业务吧。 以后 跳槽 选择更多一些。可以 通过社招 再去BAT,这时候自己的方向也比较稳定。缺点:不是大厂
+
+如果对字节有情节,去也可以的,大厂福利待遇都不错,缺点:要考虑自己以后的方向。
+
+
+## 百度和华为
+
+
+
+针对于你的问题,我挨个说一下哈:
+
+1. 大华是做安防的,和主流互联网偏了一些。
+2. 成都有没有招人的机会,这个我也确定不了,但可以确定的是,第一份工作确实很重要!对以后的发展还是有很大影响的。 不过和 女朋友异地 如何权衡还是要看你自己。
+3. 百度大数据 也有做toB,就是给企业提供服务,做toB是比较辛苦,而且赚的不多(这里指的是部门营收),不过相对于你的其他几个offer,我倾向于你选百度,百度对应届生的培养还是很到位的。对你以后的技术发展有帮助。 而且大数据做tob的不止百度一家,阿里云,腾讯云,等等很多都做大数据toB,以后跳槽也容易。
+4. 这种情况有没有救,我也不清楚了,大概率是不太行了,不用过于纠结,能抓住目前的机会就很好了。
+
+
+## 大华和小米
+
+
+
+倾向于选小米吧,大华是做安防的,**在安防公司里做客户端,可以说是偏上加偏了**。
+
+关于 小米南京工资 我也不了解,不过一般来说 南京工资都会低一些。
+
+小米手机部门,以后你的选择 也会多一些,毕竟国内这么多手机厂商,而且小米的发展势头还是可以的,最近小米在发力小米汽车,如果能内部转岗到小米汽车,就很不错了,这是未来十年的一个重大机会,可以跟着雷总起飞。
+
+在看以后定居,南京的房价可比杭州亲民多了,南京也就2w一平左右,以后你在南京定居基本压力不大,如果算上房价,杭州大华多出来的那点工资 简直不值一提了。
+
+# 总结
+
+最后我也只是针对大家给我的情况,我来做一个基本的分析,给出我的判断。
+
+毕竟最了解你的,还是你自己,而且入职之后 工作具体内容,部门发展,其实我们都无法预测,只能结合我们能确定的内容来做分析。
+
+拿我自己来举例,我当初毕业拿到是腾讯互娱XX工作室的后端开发offer 和 华为2012 数据库部门的offer,当然还有其他offer就不提了,那么当时问身边朋友前辈,一定是选 腾讯了,我也倾向于腾讯,但这么多年过后 反过来看,我感觉当初如果去华为可能更好一些。
+
+具体原因我也会在知识星球里做分享。
+
+所以 **在选择offer上,是有很多是未知的,再好的部门也有坑,再差的部门 遇到好领导也会很舒服**。
+
+**我们只能把握住 目前能把握的,至于后面怎么样,只有经历了才知道**。
+
+录友们在选择offer上,也多和问一问身边的同学,前辈们,多方面接受建议,在结合自己的情况做出判断,也希望录友们都有一个好的发展,加油💪
+
diff --git a/problems/知识星球精选/初入大三选择考研VS工作.md b/problems/知识星球精选/初入大三选择考研VS工作.md
new file mode 100644
index 00000000..ba675761
--- /dev/null
+++ b/problems/知识星球精选/初入大三选择考研VS工作.md
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+# 初入大三,考研VS工作
+
+9月份开学季,已过,一些录友也升入大三了,升入大三摆在自己面前最大的问题就是,考研还是找工作?
+
+在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里就有录友问我这样一个问题, 其实每个人情况不一样,做出的选择也不一样,这里给大家分享一下,相信对你也会有启发。
+
+
+
+以下是我的回答:
+
+首先我是考过研的,比较幸运一次就上岸了,这里说一下我的心得。
+
+你才刚刚大三 就已经做了这么充分的准备了,那我倾向于 选择直接工作。
+
+因为现在你准备的这些,都是找工作需要的,也都是实用的技术。
+
+如果你明年初就开始准备考研了,那么你现在学的这些东西,就是半途而废了,考研一年 能让你的 编程技能水平 回到解放前(考过研的同学应该都懂的)。
+
+不能说考研的内容一点用都没有,如果从技术学习的角度来说,其投入产出性价比极其极其极其的低。
+
+举一个不太恰当的例子,考研就是大家一起学 “一个不太实用的知识”,看谁学的好。
+
+所以考研其实更多的是学历上的提升,如果想通过考研,或者读研学习到什么? **还是不要有这个打算,大概率会让你失望的**。
+
+正如你所说的,你有信心成为年级里比较优秀的(就业方面),也正是 准备的早,所以给了自己信心。
+
+而且你们学校还有很多学长本科毕业就找到了好的工作,完全可以追随他们的足迹。
+
+去考研的话,有信心考上更好的学校,当然可以,关键是 考研也是千军万马过独木桥,特别是计算机考研,特别是985名校,非常的卷。
+
+如果没考上研究生,再去找工作就很被动了。
+
+这也是为什么,很多一战失利都会选择二战,因为如果失败,损失很大,所以这条路还要继续走下去,一定要上岸。
+
+再结合自己的情况,假如能考上,但考上了一所一般学校,其实对自己来说都是损失。 毕业之后 未必 有现在直接找工作找的好,年轻就是优势,特别是做研发,读研出来也是做研发,本科也是做研发,其实没太大区别的。
+
+所以 如果本科毕业的学长学姐 就业也不错,可以追随他们的脚步,毕竟你已经开始准备了。
+
+**如果有信心要冲 名校计算机研究生,或者说对某一所大学有情节,添补高考遗憾,那么可以冲,考上了是值得的**。
+
+
+当然也可以多和身边的 师兄 师姐交流,看看他们的说法,综合评估一下。
+
diff --git a/problems/知识星球精选/天下乌鸦一般黑.md b/problems/知识星球精选/天下乌鸦一般黑.md
new file mode 100644
index 00000000..29543747
--- /dev/null
+++ b/problems/知识星球精选/天下乌鸦一般黑.md
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+# 天下乌鸦一般黑,哪家没有PUA?
+
+相信大家应该经常在 各大论坛啊之类的 看到对各个互联网公司的评价,有风评好的,也有风评不好的。
+
+在[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)里有录友问我这样一个问题:
+
+
+
+这位录友,拿了阿里云,腾讯,百度,shopee的意向书,可以确是收割机了,但如果还没有进入职场,还容易被网上这些风评误导。
+
+卡哥来客观的分析一下,如何看到这些网上对公司的评论。
+
+脉脉,知乎上喷阿里,百度的 都比较多。喷腾讯的确实少一些。
+
+**只能说腾讯的舆论控制相对比较好**,在加上职能体系的人文关怀比较到位(公仔,各种活动,逢年过节小礼品之类的)。
+
+但**天下乌鸦一般黑**,腾讯的职场PUA,一点都不比阿里的少,各种套路 ,阿里有的,腾讯都有,还有什么各种花边吃瓜新闻,在腾讯内网特别多。
+
+但这些都在公司内网传播,很少传出去。 这就是腾讯厉害所在了。
+
+其实我们在选择公司的时候,**主要是看岗位,看业务,看发展**,至于 有没有PUA之类的,只能说**有人的地方就有江湖**,腾讯人 就比 阿里人 就更正直么?
+
+相信大家都参加过面试。招聘的时候,几个小时的面试能看出人品么?对吧。
+
+各种新人背锅,末尾淘汰,PUA,阿里有的,腾讯都有。 所以大家求职的时候不用在乎这些风评。
+
+至于这种锅和套路 能不能落到自己的头上,就要看碰到了什么样的直属领导了。
+
+例如两位同学去了同一家公司,同一个事业群,同一个部门,同一个项目组,只是在两个不同的领导下干活,其区别都可以一个天上,一个地上。
+
+有的录友 可能对职场套路不太了解,或者 初入职场比较顺利,没有感受过什么套路。
+
+这里卡哥给大家随便说一个,例如,一个项目组,有前端组和后端组,分别是两个老大,有一个需求,要开发一个功能,这个功能本来前端就可以独立完成的,但上线可能会有风险,保护自己手下的前端领导,就会让前端同学和后端的同学一起实现这个功能,也就是前端实现一部分,后端也要做一部分数据处理,前端展示就可以了。
+
+为什么这么安排呢?
+
+因为一旦上线出问题了,就是前端和后端一起背锅,这样前端同学压力就小很多了。
+
+而整个需求安排,前端同学其实并不知道 自己的风险,其实是领导保护了他。
+
+那么 不保守下手的领导,当然就啥也不说了,让你一个人把这个功能做了,上线没出问题 那还算万事大吉,一旦出问题,那年底考核是不是就要背一个指标了。
+
+所以不要感觉程序员的工作环境很单纯,其实套路多得很,还是那句话:**有人的地方就有江湖**,不区分公司的。
+
+只能说 业务发展越好的部门,套路相对来说少一点,毕竟高速发展可以掩盖很多问题。
+
+**所以遇到什么样的直属领导非常非常的重要**,但这又是我们决定不了的。 所以这都看缘分(运气)了。
+
+有的同学毕业在大厂顺风顺水,除了自己努力外(而大家谁又不努力呢?),更重要的是遇到了好领导。
+
+但有的同学同样进大厂,发展就很差,而且没人给他指引一些部门潜在的规则,那就难免会撞坑。
+
+未必是他不够努力,不够聪明,不会沟通,可能恰巧 部门效益不好,部门考核就差,领导一般不会让老人背锅,毕竟系统的bug都是老人写的,老人都走了,谁来修bug呢(人间真实)。
+
+那领导就拿他这个新人开刀了呗。
+
+所以,**同样是进大厂,发展好的同学 不用过于优越感,感觉是自己能力多强,其实大概率是赶上了 好部门好领导,发展不好的同学也不要 自责自己能力不行,甚至开始自卑,大概率是运气不太好而已**。
+
+那么是 发展好坏全看运气了么,当然不是!
+
+重要是 遇到挫折(背锅,绩效不好,甚至被开除),不要自卑,不要放弃,相信自己,只要把时间拉长,5-10年的时间,**真正努力的人,发展都不错!**
+
+卡哥希望录友们都有好的发展,加油💪
+
+
diff --git a/problems/知识星球精选/非科班2021秋招总结.md b/problems/知识星球精选/非科班2021秋招总结.md
new file mode 100644
index 00000000..c2c7ed33
--- /dev/null
+++ b/problems/知识星球精选/非科班2021秋招总结.md
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+# 非科班,收获满满!
+
+九月份悄然已过,秋招已经快接近尾声了,星球里已经纷纷有录友开始写这次的秋招总结。
+
+其中一位录友写的很好,所以想分享出来 给公众号上的录友也看一看,相信对大家有所启发,特别是明年要找工作的录友,值得好好看一看。
+
+这篇总结首发在代码随想录[知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)上,立刻就获得了60个赞,很多评论,我这里放出一个截图:
+
+
+
+以下是星球上该录友的总结:
+
+--------------------
+
+211本硕非科班菜鸡转码不到一年,从最开始的迷茫到后面认识到差距的焦虑再到后面逐渐恢复坦然的心态,一路起起伏伏,但也算连滚带爬的趟了过来,**感激一路上耐心为我答疑解惑的各路大佬,尤其是咱们卡哥哈哈**。
+
+秋招收获如下(按收到意向顺序):
+
+* 诺瓦星云 西安 软件开发工程师 提前批意向书
+* 字节跳动 抖音客户端开发工程师 提前批意向书
+* 滴滴 网约车部门后端开发工程师C++/Go 提前批意向书
+* 腾讯 IEG光子工作室技术中心测试开发 正式批意向书
+* 美团 基础研发平台后端开发工程师JAVA 正式批意向书
+* 阿里 阿里云计算平台后端开发工程师C++ 正式批意向书
+
+被终结的岗位:
+* 蔚来 提前批后端三面挂
+* 百度/京东 后端提前批无音讯,正式批笔试我就都拒了
+* 网易 正式批一面过,但感觉不喜欢,二面就放弃了
+* 虾皮 提前批二面挂(北京hc太少,卷不动,秋招甚至直接不放岗)
+* 蓝湖 提前批二面挂(面完字节三面之后半个小时紧接着蓝湖二面,字节面了两个小时,人都麻了,强烈建议大家面试不要排太挤!!)
+* 招银网络 正式批一面过,二面放弃
+* 商汤、oppo、知乎 提前批简历挂,后面懒得投了
+
+# 秋招历程
+
+## 开始准备
+
+最开始的准备是从**去年十月份左右开始**,那个时候刚开始意识到自己将来找工作的问题,就选择了一门自己相对来说有一些基础的C++开始入手学习,看到网上的很多经验都说语言不是最大的问题,能学好一门后面转型都很快,所以并没有在这个问题上有什么纠结,大家看我拿到的岗位也可以发现事实确实如此。
+
+**从十月份开始看C++ Primer这本书**,断断续续花了三个多月,确实拉胯。
+
+当时主要是事情太多,而且我在熟悉完主要的语法和特性之后,大概一个月的时间吧,就开始上手刷leetcode了,入门真的很痛苦,递归啥的看一遍忘一遍,一天吭哧吭哧弄下来也就两三道题,还基本都不是自己写出来的,因为我光理解别人的方法就需要很长时间。
+
+**后面刷题解刷到了卡哥,着实幸运,跟着卡哥的题解我也逐渐有了自己的方法模式和比较规范的代码风格**,所以到后面尽管有时候会发现也会有比卡哥更好的方法,我还是愿意先上手走一遍卡哥的思路,之后再补充别的。
+
+**不得不说,题解能跟住一个人确实很有必要**,有的题卡哥没有出题解,我也是先找到之前卡哥类似的题目找思路,再自己写出来。整个刷题的流程持续到过年,我就开始刷剑指offer了,基本简单题都可以撕,中等困难的还是只能看题解。
+
+我个人的经验是不愿意在思考题解上浪费太多时间,**如果打眼一看就知道自己不太可能做出来,我会选择直接看题解**,省下的时间哪怕自己多敲两遍也比对着屏幕发呆效率高,毕竟面试考察的不是你创造算法的能力,会用就行了,当然这只是个人见解,大佬息怒。
+
+刷完剑指offer大概花了半个月的时间,**时间也来到了三月份**,周围的不少人已经开始找春招实习,但更多的人还是和我一样,由于各种原因没法去找实习。
+
+这个时候各种情绪都会有,焦虑,迷茫,没办法,改变不了现实情况只能尽可能的提升自己。
+
+这个时候我的算法已经比较熟练了,基本一天不用太多时间也能过四道题,尽管其中仍有不少是对着题解敲的,但是对别人思路的理解确实已经练得轻车熟路了,我觉得这也是一种进步吧。
+
+**四月份开始准备项目**,没错,就是烂大街的webserver,大家都知道这个项目烂大街,但是经过后面的各种面试我也发现,不管你是什么项目,对于面试官来说都很基础。
+
+哪怕是大厂实习的人又有几个能接触到核心,当然这也是对大部分人说的,实习大佬勿喷。**所以面试考察的就是你对基础的掌握**,就算你讲了项目各种高大上的方法,虽然可能有加分,但也是在给自己埋坑。
+
+比如面试官可能问你有没有看过这个技术具体实现源码等等。
+
+**把自己捧的越高,一旦被发现基础有漏洞,摔得也越惨**,面试官对每个人都会有一个心理预期,比如我可能就因为非科班占了一些心理预期比较低的便宜,也就是不容易让对方失望,客户端我0基础,测开0基础,但是都过了,当然像我这样的坏处就是offer大概率只是白菜,所以综合来看有利有弊,大家自己权衡。
+
+
+**搞这个webserver连带各种计网,操作系统的学习花了两个月的时间**。之后便开始了面向面经自习的流程。
+
+这个时候算法题基本不再做新的了,力扣累计刷题已经接近400,我知道里面不少题就算再拿给我,我也不一定会做,所以做新题有什么意义呢,能把之前的高频题,热题刷好就已经超过很多人了。
+
+因为之前做题都是自己按标签做,后面看到卡哥出了系列题解,基本都是我之前做过的,所以**花了一周左右就把卡哥的pdf全过了一遍,帮助很大**。
+
+## 提前批
+
+**后面六七月份的提前批我参与的不是特别积极**,和大多数人一样,我也总想着自己还没准备好,但是总得跨出第一步,所以就先找了一些小厂练手。
+
+不过牛客上投的小厂基本都没有音讯,真正想投递还是官网最靠谱。
+
+诺瓦是我的第一份offer,所以尽管我大概率去不了,我依然心怀感激,**因为经历过的人都知道第一份offer对于一个迷茫的秋招生来说是多么的宝贵**。
+
+后面拿到字节和滴滴我着实没有想到,因为感觉自己的表现还有待提升,但能过肯定是开心的。
+
+**提前批没有笔试,所以七月份的提前批窗口确实非常宝贵**。
+
+## 正式秋招
+
+八月份之后就比较正常了,基本就是笔试,面试等等,**可以分享的一点是腾讯、阿里这种大厂不是特别看重笔试**,因为很多人在笔试之前就走完面试流程了,但是对于有一些劣势的同学还是希望能认真对待笔试,争取让自己多一个闪光点。
+
+后期的算法题主要都集中在高频题、热题上面,所以还是应该把剑指刷好,配合别人分享的面经来巩固,**卡哥的算法pdf可以多看多复习**,就算没有考到也会让自己安心一些。
+
+同时对于基础知识的整理更多的应该从面经中获取,我个人秋招下来总共看了得有至少500份面经,其实别人的面经和自己面试没啥区别。
+
+同时也因为看了太多的面经,我自己的面经就不需要太多的整理了,除了一些没答上来的关键问题,因为基本都被之前的涵盖了,所以与其海投参加一些不靠谱的面试,倒不如整理十份面经来得实在。
+
+参加面试主要是锻炼临场的心态,但是大厂和小厂的面试确实是有区别的,所以大厂的面经一定要多看多整理。
+
+
+## 感想
+
+一口气写下来就已经2000字了,最后还是多说两句,分享一点感想吧。
+
+**除了超级大佬,基本每一个秋招生都会有过迷茫,焦虑的心路历程**。
+
+一方面我们需要认识到自己的局限性,认清现实。
+
+另一方面也应该看到自己能改变的现实,许多人的时间真的只是在盲目的焦虑中虚耗,这是一个死循环,浪费的时间越多后面只会越焦虑,唯一的方法就是打起精神行动起来。当然也不用把自己逼的太紧,找到合适的排解方式,比如打会儿球打会儿游戏,让自己运行在一个正确的,符合自己节奏的轨道上不断前进。
+
+**面试是玄学,有些人的就是难,有些人的就是简单**,没有人能保证你每次都简单,但也不会每次都难,我们努力提升实力只是为了能创造更多机会,并在机会出现的时候把握住。
+
+我觉得一个人最大的幸运就是付出的努力能有收获,所以我希望大家都能幸运地结束秋招,也希望我能继续不忘初心,保持谦逊。秋招只是人生的一段小插曲,未来的路还有很长很长,写下这篇流水账结束我的秋招,也希望能与诸君共勉,加油!
+
+
From 04ab9ec8945a4f4a3af504fb131d2f97f7c812c0 Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Tue, 26 Oct 2021 12:20:35 +0800
Subject: [PATCH 274/284] Update
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 9e255970..ab1e4eff 100644
--- a/README.md
+++ b/README.md
@@ -555,7 +555,7 @@
也欢迎与我交流,备注:「个人简单介绍」 + 交流,围观朋友圈,做点赞之交(备注没有自我介绍不通过哦)
-
+
# 公众号
From 1d5ec1aed1acea4e797f8d2aca83c4d5f951ab2e Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Tue, 26 Oct 2021 12:23:03 +0800
Subject: [PATCH 275/284] Update
---
problems/0037.解数独.md | 2 +-
problems/回溯总结.md | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/problems/0037.解数独.md b/problems/0037.解数独.md
index 10177c71..b7255a2a 100644
--- a/problems/0037.解数独.md
+++ b/problems/0037.解数独.md
@@ -286,7 +286,7 @@ class Solution {
```
### Python
-```python3
+```python
class Solution:
def solveSudoku(self, board: List[List[str]]) -> None:
"""
diff --git a/problems/回溯总结.md b/problems/回溯总结.md
index 421691da..50a61b9e 100644
--- a/problems/回溯总结.md
+++ b/problems/回溯总结.md
@@ -430,7 +430,11 @@ N皇后问题分析:
同样也感谢录友们的坚持,这也是我持续写作的动力,**正是因为大家的积极参与,我才知道这件事件是非常有意义的**。
-最后希望大家可以转发这篇文章给身边的朋友们,因为还有很多学习算法的小伙伴依然在浩如烟海的信息中迷茫,而我相信「代码随想录」会让大家少走弯路!
+回溯专题汇聚为一张图:
+
+
+
+这个图是 [代码随想录知识星球](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ) 成员:莫非毛,所画,总结的非常好,分享给大家。
**回溯算法系列正式结束,新的系列终将开始,录友们准备开启新的征程!**
From ecb4292a4aa4731f829363dfcbfcc30f6d36f3b3 Mon Sep 17 00:00:00 2001
From: youngyangyang04 <826123027@qq.com>
Date: Tue, 26 Oct 2021 12:51:40 +0800
Subject: [PATCH 276/284] Update
---
README.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index ab1e4eff..217d7e81 100644
--- a/README.md
+++ b/README.md
@@ -555,7 +555,8 @@
也欢迎与我交流,备注:「个人简单介绍」 + 交流,围观朋友圈,做点赞之交(备注没有自我介绍不通过哦)
-
+

+
# 公众号
@@ -566,6 +567,6 @@
**来看看就知道了,你会发现相见恨晚!**
+
-
From c5a9eadab17dcea7e9d693f144c7f2669d5f4c54 Mon Sep 17 00:00:00 2001
From: Arthur
Date: Tue, 26 Oct 2021 15:09:19 +0100
Subject: [PATCH 277/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200108.=E5=B0=86?=
=?UTF-8?q?=E6=9C=89=E5=BA=8F=E6=95=B0=E7=BB=84=E8=BD=AC=E6=8D=A2=E4=B8=BA?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md=20C=E8=AF=AD?=
=?UTF-8?q?=E8=A8=80=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0108.将有序数组转换为二叉搜索树.md | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/problems/0108.将有序数组转换为二叉搜索树.md b/problems/0108.将有序数组转换为二叉搜索树.md
index e82d6e95..7dcce649 100644
--- a/problems/0108.将有序数组转换为二叉搜索树.md
+++ b/problems/0108.将有序数组转换为二叉搜索树.md
@@ -375,8 +375,25 @@ var sortedArrayToBST = function (nums) {
};
```
+##C
+递归
+```c
+struct TreeNode* traversal(int* nums, int left, int right) {
+ if (left > right)
+ return NULL;
+ int mid = left + ((right - left) / 2);
+ struct TreeNode* root = (struct TreeNode*)malloc(sizeof(struct TreeNode));
+ root->val = nums[mid];
+ root->left = traversal(nums, left, mid - 1);
+ root->right = traversal(nums, mid + 1, right);
+ return root;
+}
-
+struct TreeNode* sortedArrayToBST(int* nums, int numsSize) {
+ struct TreeNode* root = traversal(nums, 0, numsSize - 1);
+ return root;
+}
+```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
From 79623eba4afb9700fed82d3b0a6d44fa7870e98e Mon Sep 17 00:00:00 2001
From: Arthur
Date: Tue, 26 Oct 2021 15:59:35 +0100
Subject: [PATCH 278/284] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200538.=E6=8A=8A?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91=E8=BD=AC=E6=8D=A2?=
=?UTF-8?q?=E4=B8=BA=E7=B4=AF=E5=8A=A0=E6=A0=91.md=20C=E8=AF=AD=E8=A8=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0538.把二叉搜索树转换为累加树.md | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/problems/0538.把二叉搜索树转换为累加树.md b/problems/0538.把二叉搜索树转换为累加树.md
index 6de98c6f..16b00817 100644
--- a/problems/0538.把二叉搜索树转换为累加树.md
+++ b/problems/0538.把二叉搜索树转换为累加树.md
@@ -293,6 +293,27 @@ var convertBST = function (root) {
};
```
+##C
+
+递归
+```c
+int pre;
+void traversal(struct TreeNode* node) {
+ if(!node)
+ return ;
+ traversal(node->right);
+ node->val = node->val + pre;
+ pre = node->val;
+ traversal(node->left);
+}
+
+struct TreeNode* convertBST(struct TreeNode* root){
+ pre = 0;
+ traversal(root);
+ return root;
+}
+```
+
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From 5eab2050cf9c1d419491f085796d7e788dfac317 Mon Sep 17 00:00:00 2001
From: Younglesszzz <571688981@qq.com>
Date: Wed, 27 Oct 2021 20:03:18 +0800
Subject: [PATCH 279/284] =?UTF-8?q?=E5=8F=A6=E4=B8=80=E7=A7=8D=E5=86=99?=
=?UTF-8?q?=E6=B3=95=20=E5=85=A8=E6=8E=92=E5=88=97=E2=85=A1=20Java?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/回溯算法去重问题的另一种写法.md | 39 ++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/problems/回溯算法去重问题的另一种写法.md b/problems/回溯算法去重问题的另一种写法.md
index d8125e91..8f5744b5 100644
--- a/problems/回溯算法去重问题的另一种写法.md
+++ b/problems/回溯算法去重问题的另一种写法.md
@@ -249,6 +249,45 @@ used数组可是全局变量,每层与每层之间公用一个used数组,所
Java:
+**47.全排列II**
+
+
+```java
+class Solution {
+ private List> res = new ArrayList<>();
+ private List path = new ArrayList<>();
+ private boolean[] used = null;
+
+ public List> permuteUnique(int[] nums) {
+ used = new boolean[nums.length];
+ Arrays.sort(nums);
+ backtracking(nums);
+ return res;
+ }
+
+ public void backtracking(int[] nums) {
+ if (path.size() == nums.length) {
+ res.add(new ArrayList<>(path));
+ return;
+ }
+ HashSet hashSet = new HashSet<>();//层去重
+ for (int i = 0; i < nums.length; i++) {
+ if (hashSet.contains(nums[i]))
+ continue;
+ if (used[i] == true)//枝去重
+ continue;
+ hashSet.add(nums[i]);//记录元素
+ used[i] = true;
+ path.add(nums[i]);
+ backtracking(nums);
+ path.remove(path.size() - 1);
+ used[i] = false;
+ }
+ }
+}
+
+```
+
Python:
From ff44674da3b09b87fbfcf33d20037e1d182c9baa Mon Sep 17 00:00:00 2001
From: changlua
Date: Wed, 27 Oct 2021 23:49:15 +0800
Subject: [PATCH 280/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=860151.?=
=?UTF-8?q?=E7=BF=BB=E8=BD=AC=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=87=8C=E7=9A=84?=
=?UTF-8?q?=E5=8D=95=E8=AF=8DJava=E4=B8=A4=E7=A7=8D=E8=A7=A3=E6=B3=95?=
=?UTF-8?q?=E2=91=A0=E5=AD=97=E7=AC=A6=E6=95=B0=E7=BB=84=E5=A1=AB=E5=85=85?=
=?UTF-8?q?=E2=91=A1=E5=8F=8C=E5=8F=8D=E8=BD=AC+=E7=A7=BB=E4=BD=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0151.翻转字符串里的单词.md | 88 +++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/problems/0151.翻转字符串里的单词.md b/problems/0151.翻转字符串里的单词.md
index 8d28b332..bf274263 100644
--- a/problems/0151.翻转字符串里的单词.md
+++ b/problems/0151.翻转字符串里的单词.md
@@ -300,6 +300,94 @@ class Solution {
}
```
+```java
+//解法二:创建新字符数组填充。时间复杂度O(n)
+class Solution {
+ public String reverseWords(String s) {
+ //源字符数组
+ char[] initialArr = s.toCharArray();
+ //新字符数组
+ char[] newArr = new char[initialArr.length+1];//下面循环添加"单词 ",最终末尾的空格不会返回
+ int newArrPos = 0;
+ //i来进行整体对源字符数组从后往前遍历
+ int i = initialArr.length-1;
+ while(i>=0){
+ while(i>=0 && initialArr[i] == ' '){i--;} //跳过空格
+ //此时i位置是边界或!=空格,先记录当前索引,之后的while用来确定单词的首字母的位置
+ int right = i;
+ while(i>=0 && initialArr[i] != ' '){i--;}
+ //指定区间单词取出(由于i为首字母的前一位,所以这里+1,),取出的每组末尾都带有一个空格
+ for (int j = i+1; j <= right; j++) {
+ newArr[newArrPos++] = initialArr[j];
+ if(j == right){
+ newArr[newArrPos++] = ' ';//空格
+ }
+ }
+ }
+ //若是原始字符串没有单词,直接返回空字符串;若是有单词,返回0-末尾空格索引前范围的字符数组(转成String返回)
+ if(newArrPos == 0){
+ return "";
+ }else{
+ return new String(newArr,0,newArrPos-1);
+ }
+ }
+}
+```
+
+```java
+//解法三:双反转+移位,在原始数组上进行反转。空间复杂度O(1)
+class Solution {
+ /**
+ * 思路:
+ * ①反转字符串 "the sky is blue " => " eulb si yks eht"
+ * ②遍历 " eulb si yks eht",每次先对某个单词进行反转再移位
+ * 这里以第一个单词进行为演示:" eulb si yks eht" ==反转=> " blue si yks eht" ==移位=> "blue si yks eht"
+ */
+ public String reverseWords(String s) {
+ //步骤1:字符串整体反转(此时其中的单词也都反转了)
+ char[] initialArr = s.toCharArray();
+ reverse(initialArr, 0, s.length() - 1);
+ int k = 0;
+ for (int i = 0; i < initialArr.length; i++) {
+ if (initialArr[i] == ' ') {
+ continue;
+ }
+ int tempCur = i;
+ while (i < initialArr.length && initialArr[i] != ' ') {
+ i++;
+ }
+ for (int j = tempCur; j < i; j++) {
+ if (j == tempCur) { //步骤二:二次反转
+ reverse(initialArr, tempCur, i - 1);//对指定范围字符串进行反转,不反转从后往前遍历一个个填充有问题
+ }
+ //步骤三:移动操作
+ initialArr[k++] = initialArr[j];
+ if (j == i - 1) { //遍历结束
+ //避免越界情况,例如=> "asdasd df f",不加判断最后就会数组越界
+ if (k < initialArr.length) {
+ initialArr[k++] = ' ';
+ }
+ }
+ }
+ }
+ if (k == 0) {
+ return "";
+ } else {
+ //参数三:以防出现如"asdasd df f"=>"f df asdasd"正好凑满不需要省略空格情况
+ return new String(initialArr, 0, (k == initialArr.length) && (initialArr[k - 1] != ' ') ? k : k - 1);
+ }
+ }
+
+ public void reverse(char[] chars, int begin, int end) {
+ for (int i = begin, j = end; i < j; i++, j--) {
+ chars[i] ^= chars[j];
+ chars[j] ^= chars[i];
+ chars[i] ^= chars[j];
+ }
+ }
+}
+```
+
python:
```Python
From 870fdf9824fd92ad82672b14c51a20117d42dbd2 Mon Sep 17 00:00:00 2001
From: changfubai
Date: Thu, 28 Oct 2021 17:52:04 +0800
Subject: [PATCH 281/284] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AC=94=E8=AF=AF<20?=
=?UTF-8?q?201224=E8=B4=AA=E5=BF=83=E5=91=A8=E6=9C=AB=E6=80=BB=E7=BB=93>?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/周总结/20201224贪心周末总结.md | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/problems/周总结/20201224贪心周末总结.md b/problems/周总结/20201224贪心周末总结.md
index 097ae9ed..1bc39247 100644
--- a/problems/周总结/20201224贪心周末总结.md
+++ b/problems/周总结/20201224贪心周末总结.md
@@ -6,7 +6,7 @@
在[贪心算法:用最少数量的箭引爆气球](https://programmercarl.com/0452.用最少数量的箭引爆气球.html)中,我们开始讲解了重叠区间问题,用最少的弓箭射爆所有气球,其本质就是找到最大的重叠区间。
-按照左边界经行排序后,如果气球重叠了,重叠气球中右边边界的最小值 之前的区间一定需要一个弓箭
+按照左边界进行排序后,如果气球重叠了,重叠气球中右边边界的最小值 之前的区间一定需要一个弓箭
如图:
@@ -28,7 +28,7 @@
弓箭的数量就相当于是非交叉区间的数量,只要把弓箭那道题目代码里射爆气球的判断条件加个等号(认为[0,1][1,2]不是相邻区间),然后用总区间数减去弓箭数量 就是要移除的区间数量了。
-把[贪心算法:用最少数量的箭引爆气球](https://programmercarl.com/0452.用最少数量的箭引爆气球.html)代码稍做修改,别可以AC本题。
+把[贪心算法:用最少数量的箭引爆气球](https://programmercarl.com/0452.用最少数量的箭引爆气球.html)代码稍做修改,就可以AC本题。
修改后的C++代码如下:
```CPP
@@ -60,7 +60,7 @@ public:
[贪心算法:划分字母区间](https://programmercarl.com/0763.划分字母区间.html)中我们要把这个字符串划分为尽可能多的片段,同一字母最多出现在一个片段中。
-这道题目leetcode上标的是贪心,其实我不认识是贪心,因为没感受到局部最优和全局最优的关系。
+这道题目leetcode上标的是贪心,其实我不认为是贪心,因为没感受到局部最优和全局最优的关系。
但不影响这是一道好题,思路很不错,**通过字符出现最远距离取并集的方法,把出现过的字符都圈到一个区间里**。
@@ -91,7 +91,7 @@ public:
## 总结
-本周的主题就是用贪心算法来解决区间问题,进过本周的学习,大家应该对区间的各种合并分割有一定程度的了解了。
+本周的主题就是用贪心算法来解决区间问题,经过本周的学习,大家应该对区间的各种合并分割有一定程度的了解了。
其实很多区间的合并操作看起来都是常识,其实贪心算法有时候就是常识,哈哈,但也别小看了贪心算法。
From c9845b1153addce3d5cc95ecb2864f22f5af16b7 Mon Sep 17 00:00:00 2001
From: Arthur
Date: Thu, 28 Oct 2021 12:22:05 +0100
Subject: [PATCH 282/284] =?UTF-8?q?=E4=BF=AE=E6=94=B9=200108.=E5=B0=86?=
=?UTF-8?q?=E6=9C=89=E5=BA=8F=E6=95=B0=E7=BB=84=E8=BD=AC=E6=8D=A2=E4=B8=BA?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91.md=20=E6=B3=A8?=
=?UTF-8?q?=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0108.将有序数组转换为二叉搜索树.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/0108.将有序数组转换为二叉搜索树.md b/problems/0108.将有序数组转换为二叉搜索树.md
index 7dcce649..213eb2b9 100644
--- a/problems/0108.将有序数组转换为二叉搜索树.md
+++ b/problems/0108.将有序数组转换为二叉搜索树.md
@@ -375,7 +375,7 @@ var sortedArrayToBST = function (nums) {
};
```
-##C
+## C
递归
```c
struct TreeNode* traversal(int* nums, int left, int right) {
From a8ef4fe6eeea4869dac2361566e3ed11e3d8d6a6 Mon Sep 17 00:00:00 2001
From: hailincai
Date: Fri, 29 Oct 2021 08:16:18 -0400
Subject: [PATCH 283/284] =?UTF-8?q?Update=200104.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E7=9A=84=E6=9C=80=E5=A4=A7=E6=B7=B1=E5=BA=A6.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
增加559N Java 递归方法
---
problems/0104.二叉树的最大深度.md | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md
index e20f147f..ff7cbfd1 100644
--- a/problems/0104.二叉树的最大深度.md
+++ b/problems/0104.二叉树的最大深度.md
@@ -312,6 +312,24 @@ class solution {
```
### 559.n叉树的最大深度
+```java
+class Solution {
+ /*递归法,后序遍历求root节点的高度*/
+ public int maxDepth(Node root) {
+ if (root == null) return 0;
+
+ int depth = 0;
+ if (root.children != null){
+ for (Node child : root.children){
+ depth = Math.max(depth, maxDepth(child));
+ }
+ }
+
+ return depth + 1; //中节点
+ }
+}
+```
+
```java
class solution {
/**
From 50b63f844131e703e2191cfa0442394079092708 Mon Sep 17 00:00:00 2001
From: konng
Date: Sun, 31 Oct 2021 13:19:47 +0800
Subject: [PATCH 284/284] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20golang=20=E4=BA=8C?=
=?UTF-8?q?=E5=8F=89=E6=A0=91=E9=81=8D=E5=8E=86=E7=9A=84=E6=89=80=E6=9C=89?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E7=BD=AE=E6=8D=A2=E4=B8=BA=E5=92=8C?=
=?UTF-8?q?=20c++=20=E6=A8=A1=E6=9D=BF=E7=9B=B8=E5=90=8C=E7=9A=84=E9=80=BB?=
=?UTF-8?q?=E8=BE=91=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E6=96=B0=E7=9A=84?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
之前的 golang 代码很不美观,并且他的逻辑和 c++ 的不一样,谁还专门记两个模板啊,
并且连缩进也没有,所以我就重写了一份
现在的 golang 逻辑和 c++ 相同 并且也有缩进,也没有废话代码,舒服多了
---
problems/二叉树的迭代遍历.md | 132 ++++++++++++++++-------------------
1 file changed, 60 insertions(+), 72 deletions(-)
diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md
index 6889ecc0..7aff0541 100644
--- a/problems/二叉树的迭代遍历.md
+++ b/problems/二叉树的迭代遍历.md
@@ -299,108 +299,96 @@ class Solution:
Go:
+
> 迭代法前序遍历
```go
-//迭代法前序遍历
-/**
- type Element struct {
- // 元素保管的值
- Value interface{}
- // 内含隐藏或非导出字段
-}
-
-func (l *List) Back() *Element
-前序遍历:中左右
-压栈顺序:右左中
- **/
func preorderTraversal(root *TreeNode) []int {
+ ans := []int{}
+
if root == nil {
- return nil
+ return ans
}
- var stack = list.New()
- stack.PushBack(root.Right)
- stack.PushBack(root.Left)
- res:=[]int{}
- res=append(res,root.Val)
- for stack.Len()>0 {
- e:=stack.Back()
- stack.Remove(e)
- node := e.Value.(*TreeNode)//e是Element类型,其值为e.Value.由于Value为接口,所以要断言
- if node==nil{
- continue
+
+ st := list.New()
+ st.PushBack(root)
+
+ for st.Len() > 0 {
+ node := st.Remove(st.Back()).(*TreeNode)
+
+ ans = append(ans, node.Val)
+ if node.Right != nil {
+ st.PushBack(node.Right)
+ }
+ if node.Left != nil {
+ st.PushBack(node.Left)
}
- res=append(res,node.Val)
- stack.PushBack(node.Right)
- stack.PushBack(node.Left)
}
- return res
+ return ans
}
```
> 迭代法后序遍历
```go
-//迭代法后序遍历
-//后续遍历:左右中
-//压栈顺序:中右左(按照前序遍历思路),再反转结果数组
func postorderTraversal(root *TreeNode) []int {
+ ans := []int{}
+
if root == nil {
- return nil
+ return ans
}
- var stack = list.New()
- stack.PushBack(root.Left)
- stack.PushBack(root.Right)
- res:=[]int{}
- res=append(res,root.Val)
- for stack.Len()>0 {
- e:=stack.Back()
- stack.Remove(e)
- node := e.Value.(*TreeNode)//e是Element类型,其值为e.Value.由于Value为接口,所以要断言
- if node==nil{
- continue
+
+ st := list.New()
+ st.PushBack(root)
+
+ for st.Len() > 0 {
+ node := st.Remove(st.Back()).(*TreeNode)
+
+ ans = append(ans, node.Val)
+ if node.Left != nil {
+ st.PushBack(node.Left)
+ }
+ if node.Right != nil {
+ st.PushBack(node.Right)
}
- res=append(res,node.Val)
- stack.PushBack(node.Left)
- stack.PushBack(node.Right)
}
- for i:=0;i 迭代法中序遍历
```go
-//迭代法中序遍历
func inorderTraversal(root *TreeNode) []int {
- rootRes:=[]int{}
- if root==nil{
- return nil
+ ans := []int{}
+ if root == nil {
+ return ans
}
- stack:=list.New()
- node:=root
- //先将所有左节点找到,加入栈中
- for node!=nil{
- stack.PushBack(node)
- node=node.Left
- }
- //其次对栈中的每个节点先弹出加入到结果集中,再找到该节点的右节点的所有左节点加入栈中
- for stack.Len()>0{
- e:=stack.Back()
- node:=e.Value.(*TreeNode)
- stack.Remove(e)
- //找到该节点的右节点,再搜索他的所有左节点加入栈中
- rootRes=append(rootRes,node.Val)
- node=node.Right
- for node!=nil{
- stack.PushBack(node)
- node=node.Left
+
+ st := list.New()
+ cur := root
+
+ for cur != nil || st.Len() > 0 {
+ if cur != nil {
+ st.PushBack(cur)
+ cur = cur.Left
+ } else {
+ cur = st.Remove(st.Back()).(*TreeNode)
+ ans = append(ans, cur.Val)
+ cur = cur.Right
}
}
- return rootRes
+
+ return ans
}
```