> 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 106/222] =?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 107/222] =?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 108/222] =?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 109/222] =?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 110/222] =?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 111/222] =?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 112/222] =?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
---
.../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 113/222] =?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
---
...365.有多少小于当前数字的数字.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 114/222] =?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 115/222] =?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 116/222] =?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 117/222] =?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 118/222] 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 119/222] =?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 120/222] =?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 121/222] =?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
---
.../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 122/222] =?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 123/222] =?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 124/222] =?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 125/222] =?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 126/222] =?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 127/222] =?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 128/222] =?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 129/222] =?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 130/222] =?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 131/222] =?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 132/222] =?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 133/222] =?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 134/222] =?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
---
.../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 135/222] =?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 136/222] =?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 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 137/222] =?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 138/222] =?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 139/222] =?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 140/222] =?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 141/222] =?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 142/222] =?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 143/222] =?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 144/222] 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 145/222] =?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 +-
.../0019.删除链表的倒数第N个节点.md | 2 +-
problems/0020.有效的括号.md | 2 +-
.../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 +-
.../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 +-
...序与后序遍历序列构造二叉树.md | 2 +-
....将有序数组转换为二叉搜索树.md | 2 +-
problems/0110.平衡二叉树.md | 2 +-
problems/0111.二叉树的最小深度.md | 2 +-
problems/0112.路径总和.md | 2 +-
problems/0115.不同的子序列.md | 2 +-
...个节点的下一个右侧节点指针.md | 6 +++---
problems/0121.买卖股票的最佳时机.md | 2 +-
problems/0122.买卖股票的最佳时机II.md | 2 +-
...票的最佳时机II(动态规划).md | 2 +-
.../0123.买卖股票的最佳时机III.md | 2 +-
problems/0127.单词接龙.md | 4 ++--
.../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 +-
.../0222.完全二叉树的节点个数.md | 2 +-
problems/0225.用队列实现栈.md | 2 +-
problems/0226.翻转二叉树.md | 2 +-
problems/0232.用栈实现队列.md | 2 +-
problems/0234.回文链表.md | 6 +++---
...235.二叉搜索树的最近公共祖先.md | 2 +-
.../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 +-
...309.最佳买卖股票时机含冷冻期.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 +-
.../0450.删除二叉搜索树中的节点.md | 2 +-
.../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 +-
.../0530.二叉搜索树的最小绝对差.md | 2 +-
...538.把二叉搜索树转换为累加树.md | 2 +-
problems/0541.反转字符串II.md | 2 +-
.../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 +-
.../0673.最长递增子序列的个数.md | 6 +++---
problems/0674.最长连续递增序列.md | 2 +-
problems/0684.冗余连接.md | 18 +++++++++---------
problems/0685.冗余连接II.md | 8 +++-----
problems/0700.二叉搜索树中的搜索.md | 2 +-
.../0701.二叉搜索树中的插入操作.md | 2 +-
problems/0704.二分查找.md | 2 +-
problems/0707.设计链表.md | 2 +-
....买卖股票的最佳时机含手续费.md | 2 +-
...佳时机含手续费(动态规划).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 ++--
.../1005.K次取反后最大化的数组和.md | 2 +-
problems/1035.不相交的线.md | 2 +-
...除字符串中的所有相邻重复项.md | 2 +-
problems/1049.最后一块石头的重量II.md | 2 +-
problems/1143.最长公共子序列.md | 2 +-
problems/1207.独一无二的出现次数.md | 4 ++--
problems/1221.分割平衡字符串.md | 4 ++--
...根据数字二进制下1的数目排序.md | 6 +++---
...365.有多少小于当前数字的数字.md | 4 ++--
problems/1382.将二叉搜索树变平衡.md | 8 ++++----
...超时了,此时的n究竟是多大?.md | 2 +-
...编辑距离,卡尔做了三步铺垫.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 +-
.../剑指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 +-
...溯算法去重问题的另一种写法.md | 2 +-
problems/回溯算法理论基础.md | 2 +-
problems/字符串总结.md | 2 +-
problems/数组总结篇.md | 2 +-
problems/数组理论基础.md | 2 +-
problems/栈与队列总结.md | 2 +-
problems/栈与队列理论基础.md | 2 +-
...高重建队列(vector原理讲解).md | 2 +-
problems/算法模板.md | 2 +-
problems/背包总结篇.md | 2 +-
problems/背包理论基础01背包-1.md | 2 +-
problems/背包理论基础01背包-2.md | 2 +-
.../背包问题理论基础多重背包.md | 2 +-
.../背包问题理论基础完全背包.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 146/222] =?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 147/222] 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 148/222] =?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 149/222] =?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 +-
...序数组中查找元素的第一个和最后一个位置.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 +-
.../0116.填充每个节点的下一个右侧节点指针.md | 2 +-
problems/0121.买卖股票的最佳时机.md | 2 +-
problems/0122.买卖股票的最佳时机II.md | 2 +-
.../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 +-
...买卖股票的最佳时机含手续费(动态规划).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 +-
...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 | 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 150/222] =?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 151/222] =?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 152/222] =?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 153/222] =?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 154/222] =?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 155/222] =?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 78225288cf29223a5e2c7563a0a2cfa72da3fb6f Mon Sep 17 00:00:00 2001
From: hailincai
Date: Fri, 1 Oct 2021 14:16:45 -0400
Subject: [PATCH 156/222] =?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 157/222] =?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 158/222] =?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 159/222] =?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 160/222] =?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
---
...买卖股票的最佳时机含手续费.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 161/222] =?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 162/222] =?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 163/222] =?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 164/222] =?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 165/222] =?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 166/222] =?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 167/222] =?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 168/222] =?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 169/222] =?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 170/222] =?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 171/222] =?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 172/222] =?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 173/222] =?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 174/222] =?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 175/222] =?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 176/222] =?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 177/222] =?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 178/222] =?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 179/222] =?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 180/222] =?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 181/222] =?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 182/222] =?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 183/222] =?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 184/222] =?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注释
---
.../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 185/222] =?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 186/222] =?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 187/222] =?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注释
---
...将有序数组转换为二叉搜索树.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 188/222] =?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注释
---
...38.把二叉搜索树转换为累加树.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 189/222] =?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 190/222] =?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 191/222] =?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 192/222] =?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 193/222] =?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 194/222] =?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 195/222] =?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 196/222] =?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 197/222] =?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 198/222] =?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 199/222] =?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 200/222] =?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 201/222] =?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 202/222] =?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 203/222] =?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
---
...65.有多少小于当前数字的数字.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 204/222] =?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 205/222] =?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 206/222] =?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 207/222] =?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 0d2d732378c4befa2b3ebacb5cd890dcb62981d7 Mon Sep 17 00:00:00 2001
From: Wen
Date: Wed, 13 Oct 2021 12:16:57 +0800
Subject: [PATCH 208/222] =?UTF-8?q?=E6=96=B0=E5=A2=9E=200416.=E5=88=86?=
=?UTF-8?q?=E5=89=B2=E7=AD=89=E5=92=8C=E5=AD=90=E9=9B=86.md=20Go=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/0416.分割等和子集.md | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/problems/0416.分割等和子集.md b/problems/0416.分割等和子集.md
index c8a5beea..88852e9d 100644
--- a/problems/0416.分割等和子集.md
+++ b/problems/0416.分割等和子集.md
@@ -238,6 +238,32 @@ class Solution:
return taraget == dp[taraget]
```
Go:
+```go
+// 分割等和子集 动态规划
+// 时间复杂度O(n^2) 空间复杂度O(n)
+func canPartition(nums []int) bool {
+ sum := 0
+ for _, num := range nums {
+ sum += num
+ }
+ // 如果 nums 的总和为奇数则不可能平分成两个子集
+ if sum % 2 == 1 {
+ return false
+ }
+
+ target := sum / 2
+ dp := make([]int, target + 1)
+
+ for _, num := range nums {
+ for j := target; j >= num; j-- {
+ if dp[j] < dp[j - num] + num {
+ dp[j] = dp[j - num] + num
+ }
+ }
+ }
+ return dp[target] == target
+}
+```
javaScript:
From 7484ba1e003679facc73922ab3d9eb1c909febce Mon Sep 17 00:00:00 2001
From: BarneyShi
Date: Tue, 12 Oct 2021 23:06:12 -0700
Subject: [PATCH 209/222] =?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
---
.../剑指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 210/222] =?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 211/222] =?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 212/222] =?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 213/222] =?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 214/222] =?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 215/222] =?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 216/222] =?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 217/222] =?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 218/222] =?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 219/222] =?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 220/222] 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 221/222] =?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 222/222] =?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
---
...溯算法去重问题的另一种写法.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: