+
From 5da4a7ec0edb78b465f3f00fd4ef4412bb9d5b63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A1=9C=E5=B0=8F=E8=B7=AF=E4=B8=83=E8=91=89?=
From 69bee02cf12f11cf33fbc1f86b6ae2132dde1afb Mon Sep 17 00:00:00 2001
From: aPurpleBerry <2454196228@qq.com>
Date: Sun, 5 Jan 2025 15:57:57 +0800
Subject: [PATCH 03/25] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E8=83=8C=E5=8C=85?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=E5=AE=8C?=
=?UTF-8?q?=E5=85=A8=E8=83=8C=E5=8C=85.md=20JavaScript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/背包问题理论基础完全背包.md | 44 ++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/problems/背包问题理论基础完全背包.md b/problems/背包问题理论基础完全背包.md
index 0cc6e915..ea658f7e 100644
--- a/problems/背包问题理论基础完全背包.md
+++ b/problems/背包问题理论基础完全背包.md
@@ -316,7 +316,51 @@ print(knapsack(n, bag_weight, weight, value))
### JavaScript
+```js
+const readline = require('readline').createInterface({
+ input: process.stdin,
+ output: process.stdout
+});
+let input = [];
+readline.on('line', (line) => {
+ input.push(line.trim());
+});
+
+readline.on('close', () => {
+ // 第一行解析 n 和 v
+ const [n, bagweight] = input[0].split(' ').map(Number);
+
+ /// 剩余 n 行解析重量和价值
+ const weight = [];
+ const value = [];
+ for (let i = 1; i <= n; i++) {
+ const [wi, vi] = input[i].split(' ').map(Number);
+ weight.push(wi);
+ value.push(vi);
+ }
+
+
+ let dp = Array.from({ length: n }, () => Array(bagweight + 1).fill(0));
+
+ for (let j = weight[0]; j <= bagweight; j++) {
+ dp[0][j] = dp[0][j-weight[0]] + value[0];
+ }
+
+ for (let i = 1; i < n; i++) {
+ for (let j = 0; j <= bagweight; j++) {
+ if (j < weight[i]) {
+ dp[i][j] = dp[i - 1][j];
+ } else {
+ dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - weight[i]] + value[i]);
+ }
+ }
+ }
+
+ console.log(dp[n - 1][bagweight]);
+});
+
+```
From 1d0333f59634bc68b9c4f253f95a2ef8f7a5009e Mon Sep 17 00:00:00 2001
From: Anqi Li <103280095+iqna126@users.noreply.github.com>
Date: Wed, 15 Jan 2025 17:16:40 -0800
Subject: [PATCH 04/25] =?UTF-8?q?=E7=BB=990054.=E6=9B=BF=E6=8D=A2=E6=95=B0?=
=?UTF-8?q?=E5=AD=97.md=20=E5=8A=A0=E5=85=A5python=E8=A7=A3=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/kamacoder/0054.替换数字.md | 40 +++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/problems/kamacoder/0054.替换数字.md b/problems/kamacoder/0054.替换数字.md
index de0ab1a3..e4b5c43f 100644
--- a/problems/kamacoder/0054.替换数字.md
+++ b/problems/kamacoder/0054.替换数字.md
@@ -215,6 +215,46 @@ public class Main {
}
```
+### Python:
+```python
+class Solution(object):
+ def subsitute_numbers(self, s):
+ """
+ :type s: str
+ :rtype: str
+ """
+
+ count = sum(1 for char in s if char.isdigit()) # 统计数字的个数
+ expand_len = len(s) + (count * 5) # 计算扩充后字符串的大小, x->number, 每有一个数字就要增加五个长度
+ res = [''] * expand_len
+
+ new_index = expand_len - 1 # 指向扩充后字符串末尾
+ old_index = len(s) - 1 # 指向原字符串末尾
+
+ while old_index >= 0: # 从后往前, 遇到数字替换成“number”
+ if s[old_index].isdigit():
+ res[new_index-5:new_index+1] = "number"
+ new_index -= 6
+ else:
+ res[new_index] = s[old_index]
+ new_index -= 1
+ old_index -= 1
+
+ return "".join(res)
+
+if __name__ == "__main__":
+ solution = Solution()
+
+ while True:
+ try:
+ s = input()
+ result = solution.subsitute_numbers(s)
+ print(result)
+ except EOFError:
+ break
+
+```
+
### Go:
````go
package main
From da742feaa3e324c9489bedaf867004cae583cc90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=98windscape=E2=80=99?= <2462269317@qq.com>
Date: Thu, 23 Jan 2025 11:47:27 +0800
Subject: [PATCH 05/25] =?UTF-8?q?=E4=BF=AE=E6=94=B90112.=E8=B7=AF=E5=BE=84?=
=?UTF-8?q?=E6=80=BB=E5=92=8C.md=E7=9A=84Java=E7=89=88=E6=9C=AC=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E7=9A=84=E5=AD=97=E6=AF=8D=E5=B0=8F=E5=86=99=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/0112.路径总和.md | 59 ++++++++++++++++++++-------------------
1 file changed, 31 insertions(+), 28 deletions(-)
diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md
index b97013e6..141967f5 100644
--- a/problems/0112.路径总和.md
+++ b/problems/0112.路径总和.md
@@ -309,25 +309,25 @@ public:
0112.路径总和
```java
-class solution {
- public boolean haspathsum(treenode root, int targetsum) {
+class Solution {
+ public boolean hasPathSum(TreeNode root, int targetSum) {
if (root == null) {
return false;
}
- targetsum -= root.val;
+ targetSum -= root.val;
// 叶子结点
if (root.left == null && root.right == null) {
- return targetsum == 0;
+ return targetSum == 0;
}
if (root.left != null) {
- boolean left = haspathsum(root.left, targetsum);
- if (left) { // 已经找到
+ boolean left = hasPathSum(root.left, targetSum);
+ if (left) { // 已经找到,提前返回
return true;
}
}
if (root.right != null) {
- boolean right = haspathsum(root.right, targetsum);
- if (right) { // 已经找到
+ boolean right = hasPathSum(root.right, targetSum);
+ if (right) { // 已经找到,提前返回
return true;
}
}
@@ -336,16 +336,16 @@ class solution {
}
// lc112 简洁方法
-class solution {
- public boolean haspathsum(treenode root, int targetsum) {
+class Solution {
+ public boolean hasPathSum(TreeNode root, int targetSum) {
if (root == null) return false; // 为空退出
// 叶子节点判断是否符合
- if (root.left == null && root.right == null) return root.val == targetsum;
+ if (root.left == null && root.right == null) return root.val == targetSum;
// 求两侧分支的路径和
- return haspathsum(root.left, targetsum - root.val) || haspathsum(root.right, targetsum - root.val);
+ return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);
}
}
```
@@ -353,22 +353,22 @@ class solution {
迭代
```java
-class solution {
- public boolean haspathsum(treenode root, int targetsum) {
+class Solution {
+ public boolean hasPathSum(TreeNode root, int targetSum) {
if(root == null) return false;
- stack QiLBo5a^J3N-?;Nx(1ql{vBN@9
z%Z}3}?;%dqFFV{t5Rk>HL~i4?`kG=TV@&%`zitQ3Zx5jSFC*yD{uwbiznT5U&a)FD
zWFlf*ST*g#RwpiDvy+}mjVZj^(F_WvQ5#*}yF)Id`xfX _MiJxFHs9kMoF>WFW(U~0|dvV
zezK{pxlT!;%AW^m-!%S0#lP8Z8maNw{{Gt+=ywNycbXo^Fyy~lz9SKm>&6j ~s
zjn-nw&?E3PgHI4Ct2M`5z!7@p&5-w)l}@;fl6*NNDzH7l*v|abJohIOSJG#ggrc4g
zRecEY8+Sxv?h)dD3|{BGRxKkPz~wgOd1bzWcbKRC^%1M^XStLybrn4L%JbxI?=iV|
zEkA<=W{`(=rhfnygd~{{s1_WLU(UfGfADmEMFc?Pt)H2&~VKJ$X_a5k);Uo;p2I
zO1hppFnua#w#~4$BKc0gC-^(OYsY@3zyjr2PE1(-NJYKKu)Jw{4ILe&2#;~iCeG8!
z_b7bbF-@JLBqdZ4t1K1MJ(h=>ej|k}CvGzyq7L;(%~-kHt#|I`#tC1*_GY#ZJ?1N3
z8DQraK6Hn!(WKX06y0N4>=&)+P^J9}6Ydwv_Locg4U(Ae5ItR3-yVM5FD3pydK4vb
z00ujF%sG~Nq1~AXeWL7Hxwd(e9~c9gMSkx2vbX}P7b>h^WE3gMI&jlYrqLfksj{a<
z<-+%idd9uyye?1dvFnTJ6VlYA^RMJp0gY4jKqvK4-atM?(uTX-G95E<%K@FSuQ_vU
zKCzJx`L@-$B9=~Z&_(h!JqRevJp>?6pgwT>H2mh5*ES=;McPoM(zV_V+nkM(kfhO7
zpl8V> pathsum(TreeNode root, int targetsum) {
+class Solution {
+ public List
> pathSum(TreeNode root, int targetSum) {
List
> res = new ArrayList<>();
if (root == null) return res; // 非空判断
List
> res, List
> res, List
+
From 163c3f33d8d24735230b25ddb697d726f0d5c242 Mon Sep 17 00:00:00 2001
From: Anqi Li <103280095+iqna126@users.noreply.github.com>
Date: Thu, 23 Jan 2025 08:16:44 -0800
Subject: [PATCH 06/25] =?UTF-8?q?0054.=E6=9B=BF=E6=8D=A2=E6=95=B0=E5=AD=97?=
=?UTF-8?q?.md=20=E5=9C=A8=E8=AE=B2=E8=A7=A3=E4=B8=AD=E5=8A=A0=E5=85=A5?=
=?UTF-8?q?=E4=BA=86python=20string=E4=B9=9F=E4=B8=8D=E5=8F=AF=E5=8F=98?=
=?UTF-8?q?=E7=9A=84=E8=A7=A3=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/kamacoder/0054.替换数字.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/problems/kamacoder/0054.替换数字.md b/problems/kamacoder/0054.替换数字.md
index e4b5c43f..f788d65b 100644
--- a/problems/kamacoder/0054.替换数字.md
+++ b/problems/kamacoder/0054.替换数字.md
@@ -21,7 +21,7 @@
## 思路
-如果想把这道题目做到极致,就不要只用额外的辅助空间了! (不过使用Java刷题的录友,一定要使用辅助空间,因为Java里的string不能修改)
+如果想把这道题目做到极致,就不要只用额外的辅助空间了! (不过使用Java和Python刷题的录友,一定要使用辅助空间,因为Java和Python里的string不能修改)
首先扩充数组到每个数字字符替换成 "number" 之后的大小。
From 27718a4dfca99b25ceda3ee2946130c29261be71 Mon Sep 17 00:00:00 2001
From: asnpro <920569392@qq.com>
Date: Fri, 24 Jan 2025 22:51:46 +0800
Subject: [PATCH 07/25] =?UTF-8?q?docs:=20=E4=B8=BA=200494.=E7=9B=AE?=
=?UTF-8?q?=E6=A0=87=E5=92=8C.md=20=E5=AE=8C=E5=96=84=20JavaDoc=20?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A,=20=E6=B7=BB=E5=8A=A0=E5=8A=A8=E8=A7=84?=
=?UTF-8?q?=E4=BA=94=E9=83=A8=E6=9B=B2=E6=B3=A8=E9=87=8A,=20=E8=A7=84?=
=?UTF-8?q?=E8=8C=83=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?,=20=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E5=8F=98=E9=87=8F?=
=?UTF-8?q?=E5=90=8D=E4=BB=A5=E5=A2=9E=E5=BC=BA=E4=BB=A3=E7=A0=81=E8=AF=AD?=
=?UTF-8?q?=E4=B9=89=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0494.目标和.md | 59 ++++++++++++++++++++++++++++++++++-------
1 file changed, 49 insertions(+), 10 deletions(-)
diff --git a/problems/0494.目标和.md b/problems/0494.目标和.md
index 4a1fc6ab..c38ba7e4 100644
--- a/problems/0494.目标和.md
+++ b/problems/0494.目标和.md
@@ -825,30 +825,69 @@ func abs(x int) int {
### JavaScript
```javascript
+/**
+ * 题目来源: {@link https://leetcode.cn/problems/target-sum/}
+ *
+ * 题解来源: {@link https://programmercarl.com/0494.%E7%9B%AE%E6%A0%87%E5%92%8C.html#%E7%AE%97%E6%B3%95%E5%85%AC%E5%BC%80%E8%AF%BE}
+ *
+ * 时间复杂度: O(n * C), C 为数组元素总和与目标值之和的一半
+ *
+ * 空间复杂度: O(C)
+ *
+ * @param { number[] } nums
+ * @param { number } target
+ * @return { number }
+ */
const findTargetSumWays = (nums, target) => {
+ // 原题目可转化为:
+ //
+ // 将所有元素划分为 2 个集合,
+ // 一个集合中包含所有要添加 "+" 号的元素, 一个集合中包含所有要添加 "-" 号的元素
+ //
+ // 设两个集合的元素和分别为 positive 和 negative, 所有元素总和为 sum, 那么有如下等式:
+ // positive + negative = sum (1)
+ // positive - negative = target (2)
+ // (1) 与 (2) 联立可得: positive = (sum + target) / 2,
+ // 所以如果能从原数组中取出若干个元素形成 1 个元素总和为 (sum + target) / 2 的集合,
+ // 就算得到了 1 种满足题意的组合方法
+ //
+ // 因此, 所求变为: 有多少种取法, 可使得容量为 (sum + target) / 2 的背包被装满?
- const sum = nums.reduce((a, b) => a+b);
+ const sum = nums.reduce((a, b) => a + b);
- if(Math.abs(target) > sum) {
+ if (Math.abs(target) > sum) {
return 0;
}
- if((target + sum) % 2) {
+ if ((target + sum) % 2) {
return 0;
}
- const halfSum = (target + sum) / 2;
-
- let dp = new Array(halfSum+1).fill(0);
+ const bagWeight = (target + sum) / 2;
+
+ // 1. dp 数组的含义
+ // dp[j]: 装满容量为 j 的背包, 有 dp[j] 种方法
+ let dp = new Array(bagWeight + 1).fill(0);
+
+ // 2. 递推公式
+ // dp[j] = Σ(dp[j - nums[j]]), (j ∈ [0, j] 且 j >= nums[j])
+ // 因为 dp[j - nums[j]] 表示: 装满容量为 j - nums[j] 背包有 dp[j - nums[j]] 种方法
+ // 而容量为 j - nums[j] 的背包只需要再将 nums[j] 放入背包就能使得背包容量达到 j
+ // 因此, 让背包容量达到 j 有 Σ(dp[j - nums[j]]) 种方法
+
+ // 3. dp 数组如何初始化
+ // dp[0] = 1, dp[1 ~ bagWeight] = 0
dp[0] = 1;
-
- for(let i = 0; i < nums.length; i++) {
- for(let j = halfSum; j >= nums[i]; j--) {
+
+ // 4. 遍历顺序
+ // 先物品后背包, 物品从前往后遍历, 背包容量从后往前遍历
+ for (let i = 0; i < nums.length; i++) {
+ for (let j = bagWeight; j >= nums[i]; j--) {
dp[j] += dp[j - nums[i]];
}
}
- return dp[halfSum];
+ return dp[bagWeight];
};
```
From e6698cbac457714427f4a9cba6ea2a3ea9eed94c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=98windscape=E2=80=99?= <2462269317@qq.com>
Date: Sat, 25 Jan 2025 11:52:09 +0800
Subject: [PATCH 08/25] =?UTF-8?q?=E4=BF=AE=E6=94=B90530.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A0=91=E7=9A=84=E6=9C=80=E5=B0=8F=E7=BB=9D?=
=?UTF-8?q?=E5=AF=B9=E5=B7=AE.md=E7=9A=84Java=E7=89=88=E6=9C=AC=20?=
=?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?=E5=8C=96=E5=B9=B6=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=BB=9F=E4=B8=80?=
=?UTF-8?q?=E8=BF=AD=E4=BB=A3=E6=B3=95=E7=9A=84=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0530.二叉搜索树的最小绝对差.md | 46 +++++++++++++++----------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/problems/0530.二叉搜索树的最小绝对差.md b/problems/0530.二叉搜索树的最小绝对差.md
index 2533a618..b6d08dbe 100644
--- a/problems/0530.二叉搜索树的最小绝对差.md
+++ b/problems/0530.二叉搜索树的最小绝对差.md
@@ -153,23 +153,27 @@ public:
递归
```java
class Solution {
- TreeNode pre;// 记录上一个遍历的结点
+ TreeNode pre; // 记录上一个遍历的结点
int result = Integer.MAX_VALUE;
+
public int getMinimumDifference(TreeNode root) {
- if(root==null)return 0;
- traversal(root);
- return result;
+ if (root == null)
+ return 0;
+ traversal(root);
+ return result;
}
- public void traversal(TreeNode root){
- if(root==null)return;
- //左
+
+ public void traversal(TreeNode root) {
+ if (root == null)
+ return;
+ // 左
traversal(root.left);
- //中
- if(pre!=null){
- result = Math.min(result,root.val-pre.val);
+ // 中
+ if (pre != null) {
+ result = Math.min(result, root.val - pre.val);
}
pre = root;
- //右
+ // 右
traversal(root.right);
}
}
@@ -182,22 +186,27 @@ class Solution {
TreeNode pre = null;
int result = Integer.MAX_VALUE;
- if(root != null)
+ if (root != null)
stack.add(root);
- while(!stack.isEmpty()){
+
+ // 中序遍历(左中右),由于栈先入后出,反序(右中左)
+ while (!stack.isEmpty()) {
TreeNode curr = stack.peek();
- if(curr != null){
+ if (curr != null) {
stack.pop();
- if(curr.right != null)
+ // 右
+ if (curr.right != null)
stack.add(curr.right);
+ // 中(先用null标记)
stack.add(curr);
stack.add(null);
- if(curr.left != null)
+ // 左
+ if (curr.left != null)
stack.add(curr.left);
- }else{
+ } else { // 中(遇到null再处理)
stack.pop();
TreeNode temp = stack.pop();
- if(pre != null)
+ if (pre != null)
result = Math.min(result, temp.val - pre.val);
pre = temp;
}
@@ -674,3 +683,4 @@ public class Solution
+
From c2e95f6c25b2c3f9ff61dc0891cc08360b676bb1 Mon Sep 17 00:00:00 2001
From: dam <1782067308@qq.com>
Date: Sun, 26 Jan 2025 12:08:15 +0800
Subject: [PATCH 09/25] =?UTF-8?q?108=E5=86=97=E4=BD=99=E8=BF=9E=E6=8E=A5?=
=?UTF-8?q?=20java=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/kamacoder/0108.冗余连接.md | 75 +++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/problems/kamacoder/0108.冗余连接.md b/problems/kamacoder/0108.冗余连接.md
index efbbb6d2..df3dd4de 100644
--- a/problems/kamacoder/0108.冗余连接.md
+++ b/problems/kamacoder/0108.冗余连接.md
@@ -176,6 +176,81 @@ int main() {
### Java
+```java
+import java.util.Scanner;
+
+public class Main {
+ private static int[] father;
+
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+ int pointNum = scanner.nextInt();
+ father = new int[pointNum + 1];
+ init();
+ for (int i = 0; i < pointNum; i++) {
+ join(scanner.nextInt(), scanner.nextInt());
+ }
+ }
+
+ /**
+ * 并查集初始化
+ */
+ private static void init() {
+ for (int i = 1; i < father.length; i++) {
+ // 让每个元素指向自己
+ father[i] = i;
+ }
+ }
+
+ /**
+ * 并查集寻根
+ *
+ * @param u
+ * @return
+ */
+ private static int find(int u) {
+ // 判断 u 是否等于自己,如果是的话,直接返回自己
+ // 如果不等于自己,就寻找根,寻找的时候,反复进行路径压缩
+ return u == father[u] ? u : (father[u] = find(father[u]));
+ }
+
+ /**
+ * 判断 u 和 v 是否同根
+ *
+ * @param u
+ * @param v
+ * @return
+ */
+ private static boolean isSame(int u, int v) {
+ return find(u) == find(v);
+ }
+
+ /**
+ * 添加 边 到并查集,v 指向 u
+ *
+ * @param u
+ * @param v
+ */
+ private static void join(int u, int v) {
+ // --if-- 如果两个点已经同根,说明他们的信息已经存储到并查集中了,直接返回即可
+ // 寻找u的根
+ int uRoot = find(u);
+ // 寻找v的根
+ int vRoot = find(v);
+ if (uRoot == vRoot) {
+ // --if-- 如果u,v的根相同,说明两者已经连接了,直接输出
+ System.out.println(u + " " + v);
+ return;
+ }
+ // --if-- 将信息添加到并查集
+ father[vRoot] = uRoot;
+ }
+
+}
+```
+
+
+
### Python
```python
From 333099a1268544306e303fcb779ffd801c0d0c92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=98windscape=E2=80=99?= <2462269317@qq.com>
Date: Mon, 3 Feb 2025 20:13:41 +0800
Subject: [PATCH 10/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E6=80=BB=E7=BB=93=E7=AF=87.md=E4=B8=80=E5=A4=84?=
=?UTF-8?q?=E5=88=97=E8=A1=A8=E7=BA=A7=E5=88=AB=E7=9A=84=E6=A0=BC=E5=BC=8F?=
=?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/二叉树总结篇.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/problems/二叉树总结篇.md b/problems/二叉树总结篇.md
index 8db40d65..4794233a 100644
--- a/problems/二叉树总结篇.md
+++ b/problems/二叉树总结篇.md
@@ -92,10 +92,9 @@
* 递归:中序,双指针操作
* 迭代:模拟中序,逻辑相同
* [求二叉搜索树的众数](https://programmercarl.com/0501.二叉搜索树中的众数.html)
-
+
* 递归:中序,清空结果集的技巧,遍历一遍便可求众数集合
- * [二叉搜索树转成累加树](https://programmercarl.com/0538.把二叉搜索树转换为累加树.html)
-
+* [二叉搜索树转成累加树](https://programmercarl.com/0538.把二叉搜索树转换为累加树.html)
* 递归:中序,双指针操作累加
* 迭代:模拟中序,逻辑相同
@@ -163,3 +162,4 @@
+
From add956a0e1581d1470bfcc18e01c2a175d7d358d Mon Sep 17 00:00:00 2001
From: programmercarl <826123027@qq.com>
Date: Sun, 16 Feb 2025 14:36:05 +0800
Subject: [PATCH 11/25] Update
---
problems/0416.分割等和子集.md | 12 ++++++------
problems/0695.岛屿的最大面积.md | 4 ++--
problems/kamacoder/0098.所有可达路径.md | 2 +-
problems/kamacoder/0099.岛屿的数量广搜.md | 2 +-
problems/kamacoder/0100.岛屿的最大面积.md | 2 +-
problems/kamacoder/0101.孤岛的总面积.md | 15 ++++++---------
problems/kamacoder/图论深搜理论基础.md | 2 +-
problems/kamacoder/图论理论基础.md | 23 +++++++++++++++++++++++
8 files changed, 41 insertions(+), 21 deletions(-)
diff --git a/problems/0416.分割等和子集.md b/problems/0416.分割等和子集.md
index 55ed7ad2..902c022a 100644
--- a/problems/0416.分割等和子集.md
+++ b/problems/0416.分割等和子集.md
@@ -60,7 +60,7 @@
* [动态规划:关于01背包问题,你该了解这些!](https://programmercarl.com/背包理论基础01背包-1.html)
* [动态规划:关于01背包问题,你该了解这些!(滚动数组)](https://programmercarl.com/背包理论基础01背包-2.html)
-### 01背包问题
+## 01背包问题
01背包问题,大家都知道,有N件物品和一个最多能背重量为W 的背包。第i件物品的重量是weight[i],得到的价值是value[i] 。每件物品只能用一次,求解将哪些物品装入背包里物品价值总和最大。
@@ -92,7 +92,7 @@
动规五部曲分析如下:
-1. 确定dp数组以及下标的含义
+### 1. 确定dp数组以及下标的含义
01背包中,dp[j] 表示: 容量(所能装的重量)为j的背包,所背的物品价值最大可以为dp[j]。
@@ -104,7 +104,7 @@
而dp[6] 就可以等于6了,放进1 和 5,那么dp[6] == 6,说明背包装满了。
-2. 确定递推公式
+### 2. 确定递推公式
01背包的递推公式为:dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
@@ -113,7 +113,7 @@
所以递推公式:dp[j] = max(dp[j], dp[j - nums[i]] + nums[i]);
-3. dp数组如何初始化
+### 3. dp数组如何初始化
在01背包,一维dp如何初始化,已经讲过,
@@ -133,7 +133,7 @@
vectorT1r}!k8D0?e_W;V
z%QP+<`MN$GE!OR42W)Q*hUg=r?X>BFgMvF=V_qD3i*Nq8R(5N8_A57kV}5Kk?{4;{
zQjBuli+PKy^i7rEwh*5bzd?dN^F#{)$Avz4*{ib3K50|40o%ln!e%Wg12vBvT?R4+
zdLidlK~~+t(UZsOfB2uj(0k$1(zgG!vEcbQM_j_f#R3Yhgm>s4?QatzL|SBUQlt3R
zxp=OkKK**-L(8(GXf@)^r35OvkkLk=A;DH(TA#_l*~@L{2*P%vMGSSVcG&5;(k#?8
zDKLbl)?Zoso3&^2j`8;JQpXL)g<085aOlB5L0so6@+0#bwv{G1by3b=?AzADS}3>q
z5^Y#vC-2LQkNclL(%UN7&1b75tRl7Xs(
26mzXie)SK(HEK8&NH0J9q1s&d
zk;
nmnoL9?xzk4dOM5)+3X@O;
zx#xhbVYMXZ-o?DitV@xRwq=E-jh77EhM0^^>8^XL9AtH?VS3G>
UGXZ8UP{*m=&X|c_tA|Z3>
zPqPrwM-_PGyFq52sF(UV&!2hud=smCdkO-#s=&NI-oeDO%*|+RkO_3J8du!{9r2`>
z_GbcxvRqYC$#$BrAAgAxTo(Sug_L?YFOiVPUQF;Xm5aKByv&rFzJ@lw6OWkZ3n>vO
zS+5slsf~HJbj>N^z7yY=&6VOtgv)UGo)7Y{E>j*dL4xyxzBK@hc*EMD3G*NubPu^_
zvN{NZ<`7K$@Q>+?kXw^+be#csst{ha@nYA$IhkM&wb=r1Be2u;jqzuiYwg
-4M%eH))1U=2Uo_wVDKmCC7e+jl&7!UpYzkwW;G
zK~g@GmiE5^m*?8b%N4KBXil{$=lNRkGD>0tIZSBJ()Yz0v>sqQQ_V`^)eQ8ahStx&
znMp2uVtEB@z)a_vK}?A*QD1^*EBQw)ziVu(K9dmLvcB`@RdS_UMRY|z%
Q?}8FaVOST_HKCw`bOs^od_TV1n2Tqs({+
zG>UZPG?E{-Nu@;3iDhcbtR1%ochami)DFoLz@nA_ovg<};i;OclgJ9<*9Sg$^@I%n
zi}+9OBP-9EwYhk8ZLb)f6u!4JT&OL`X!Q@x-q#SB