From 00a4cdc161413dccf044b3b573a3d87cacf276d0 Mon Sep 17 00:00:00 2001 From: zhengprince Date: Thu, 25 Apr 2024 15:21:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?Update=200494.=E7=9B=AE=E6=A0=87=E5=92=8C.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改错字:中->种 --- problems/0494.目标和.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/0494.目标和.md b/problems/0494.目标和.md index cacf6dfa..a3d79d2b 100644 --- a/problems/0494.目标和.md +++ b/problems/0494.目标和.md @@ -173,9 +173,9 @@ dp[j] 表示:填满j(包括j)这么大容积的包,有dp[j]种方法 * 已经有一个1(nums[i]) 的话,有 dp[4]种方法 凑成 容量为5的背包。 * 已经有一个2(nums[i]) 的话,有 dp[3]种方法 凑成 容量为5的背包。 -* 已经有一个3(nums[i]) 的话,有 dp[2]中方法 凑成 容量为5的背包 -* 已经有一个4(nums[i]) 的话,有 dp[1]中方法 凑成 容量为5的背包 -* 已经有一个5 (nums[i])的话,有 dp[0]中方法 凑成 容量为5的背包 +* 已经有一个3(nums[i]) 的话,有 dp[2]种方法 凑成 容量为5的背包 +* 已经有一个4(nums[i]) 的话,有 dp[1]种方法 凑成 容量为5的背包 +* 已经有一个5 (nums[i])的话,有 dp[0]种方法 凑成 容量为5的背包 那么凑整dp[5]有多少方法呢,也就是把 所有的 dp[j - nums[i]] 累加起来。 From 5955c1de5dc8811b30c29c49121cb8ad42ff32c4 Mon Sep 17 00:00:00 2001 From: yawebNW <38253154+yawebNW@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:48:33 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Update=200332.=E9=87=8D=E6=96=B0=E5=AE=89?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E7=A8=8B.md=20=E6=9B=B4=E6=96=B0java?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit java最后一个方法新增去重逻辑,原代码遇到循环时会无限递归 --- problems/0332.重新安排行程.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/problems/0332.重新安排行程.md b/problems/0332.重新安排行程.md index 144672a9..bc453c51 100644 --- a/problems/0332.重新安排行程.md +++ b/problems/0332.重新安排行程.md @@ -379,6 +379,8 @@ class Solution { String targetLocation; //遍历从当前位置出发的机票 for (int i = 0; i < targetLocations.size(); i++) { + //去重,否则在最后一个测试用例中遇到循环时会无限递归 + if(i > 0 && targetLocations.get(i).equals(targetLocations.get(i - 1))) continue; targetLocation = targetLocations.get(i); //删除终点列表中当前的终点 targetLocations.remove(i); From c3ca80645400a5a87767020d66af6c981db5336d Mon Sep 17 00:00:00 2001 From: francisshzhu Date: Fri, 26 Apr 2024 12:50:59 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B90332.=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=AE=89=E6=8E=92=E8=A1=8C=E7=A8=8B.md=20=E4=B8=ADpython?= =?UTF-8?q?=E8=A7=A3=E6=B3=95=E7=9A=84markdown=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0332.重新安排行程.md | 1 - 1 file changed, 1 deletion(-) diff --git a/problems/0332.重新安排行程.md b/problems/0332.重新安排行程.md index 144672a9..bbe3a001 100644 --- a/problems/0332.重新安排行程.md +++ b/problems/0332.重新安排行程.md @@ -419,7 +419,6 @@ class Solution { ``` ### Python -``` 回溯 使用字典 ```python class Solution: From 1c390b3562b03be7a24933455b76a9187996ff72 Mon Sep 17 00:00:00 2001 From: xqsrpanz Date: Fri, 26 Apr 2024 18:01:03 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=20JavaScript=20?= =?UTF-8?q?=E8=A7=A3=E6=B3=95=E4=BA=8C=EF=BC=8C=E5=A0=86=20pop=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=97=A0=E6=B3=95=E5=A4=84=E7=90=86=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=20<=3D=201=20=E7=9A=84=E8=BE=B9=E7=95=8C?= =?UTF-8?q?=E6=83=85=E5=86=B5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0347.前K个高频元素.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/problems/0347.前K个高频元素.md b/problems/0347.前K个高频元素.md index 34d9f82c..8a219c6a 100644 --- a/problems/0347.前K个高频元素.md +++ b/problems/0347.前K个高频元素.md @@ -405,6 +405,11 @@ class Heap { // 获取堆顶元素并移除 pop() { + // 边界情况,只有一个元素或没有元素应直接弹出 + if (this.size() <= 1) { + return this.queue.pop() + } + // 堆顶元素 const out = this.queue[0]; @@ -608,3 +613,4 @@ impl Solution { + From bcdf3e4ecdf352ee5f6a9d539bd980c66c3ea93e Mon Sep 17 00:00:00 2001 From: xqsrpanz <129468278+xqsrpanz@users.noreply.github.com> Date: Fri, 26 Apr 2024 19:45:18 +0800 Subject: [PATCH 5/5] =?UTF-8?q?Update=200347.=E5=89=8DK=E4=B8=AA=E9=AB=98?= =?UTF-8?q?=E9=A2=91=E5=85=83=E7=B4=A0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复了 JavaScript 解法二,堆 pop 方法无法处理数组长度 <= 1 的边界情况的问题 2. 删除了有误导性的条件判断。事实上,被删除的表达式永远为真(searchChild !== undefined)。原作者想表达的意思可能是 this.queue[searchChild] !== undefined,而实际上,这个判断也是不必要的,这种情况会被后续的 this.compare(index, searchChild) > 0 判断排除。但鉴于本项目的教程性质,直接去除可能会导致语义不清,考虑酌情将原处替换为 this.queue[searchChild] !== undefined 或直接删除 --- problems/0347.前K个高频元素.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0347.前K个高频元素.md b/problems/0347.前K个高频元素.md index 8a219c6a..cca9b0ed 100644 --- a/problems/0347.前K个高频元素.md +++ b/problems/0347.前K个高频元素.md @@ -421,7 +421,7 @@ class Heap { let left = 1; // left 是左子节点下标 left + 1 则是右子节点下标 let searchChild = this.compare(left, left + 1) > 0 ? left + 1 : left; - while (searchChild !== undefined && this.compare(index, searchChild) > 0) { // 注意compare参数顺序 + while (this.compare(index, searchChild) > 0) { // 注意compare参数顺序 [this.queue[index], this.queue[searchChild]] = [this.queue[searchChild], this.queue[index]]; // 更新下标