From 6ed304e9cdb3f8bd3ef74220190f808ffbcab79d Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 14:51:45 +0800 Subject: [PATCH 01/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=A7=84=E5=88=92=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=20?= =?UTF-8?q?=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...210\222\347\220\206\350\256\272\345\237\272\347\241\200.md" | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git "a/problems/\345\212\250\346\200\201\350\247\204\345\210\222\347\220\206\350\256\272\345\237\272\347\241\200.md" "b/problems/\345\212\250\346\200\201\350\247\204\345\210\222\347\220\206\350\256\272\345\237\272\347\241\200.md" index a99c069002..bff26d1d34 100644 --- "a/problems/\345\212\250\346\200\201\350\247\204\345\210\222\347\220\206\350\256\272\345\237\272\347\241\200.md" +++ "b/problems/\345\212\250\346\200\201\350\247\204\345\210\222\347\220\206\350\256\272\345\237\272\347\241\200.md" @@ -12,7 +12,7 @@ ## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划理论基础](https://www.bilibili.com/video/BV13Q4y197Wg),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划理论基础](https://www.bilibili.com/video/BV13Q4y197Wg),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 什么是动态规划 @@ -135,3 +135,4 @@ + From b295b12d1abdacd0e3ba09d6a9395d494ede0b42 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 14:53:34 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200509.=E6=96=90?= =?UTF-8?q?=E6=B3=A2=E9=82=A3=E5=A5=91=E6=95=B0=20=E6=8E=92=E7=89=88?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...220\346\263\242\351\202\243\345\245\221\346\225\260.md" | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git "a/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" "b/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" index 7ace072334..0c073db5bb 100644 --- "a/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" +++ "b/problems/0509.\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260.md" @@ -32,9 +32,9 @@ F(n) = F(n - 1) + F(n - 2),其中 n > 1 * 0 <= n <= 30 -# 视频讲解 +## 算法公开课 -**《代码随想录》算法视频公开课:[手把手带你入门动态规划 | leetcode:509.斐波那契数](https://www.bilibili.com/video/BV1f5411K7mo),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[手把手带你入门动态规划 | leetcode:509.斐波那契数](https://www.bilibili.com/video/BV1f5411K7mo),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -278,7 +278,7 @@ class Solution: return self.fib(n - 1) + self.fib(n - 2) ``` -### Go: +### Go ```Go func fib(n int) int { if n < 2 { @@ -479,3 +479,4 @@ public class Solution + From 9b24f3cdefe2ee2ca10eb97c2cef4224cd864622 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 14:56:48 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200070.=E7=88=AC?= =?UTF-8?q?=E6=A5=BC=E6=A2=AF=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0070.\347\210\254\346\245\274\346\242\257.md" | 5 +++-- ...203\214\345\214\205\347\211\210\346\234\254.md" | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git "a/problems/0070.\347\210\254\346\245\274\346\242\257.md" "b/problems/0070.\347\210\254\346\245\274\346\242\257.md" index 1b24e49150..1a1f7e31b5 100644 --- "a/problems/0070.\347\210\254\346\245\274\346\242\257.md" +++ "b/problems/0070.\347\210\254\346\245\274\346\242\257.md" @@ -29,9 +29,9 @@ * 1 阶 + 2 阶 * 2 阶 + 1 阶 -# 视频讲解 +## 算法公开课 -**《代码随想录》算法视频公开课:[带你学透动态规划-爬楼梯|LeetCode:70.爬楼梯)](https://www.bilibili.com/video/BV17h411h7UH),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[带你学透动态规划-爬楼梯|LeetCode:70.爬楼梯)](https://www.bilibili.com/video/BV17h411h7UH),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -522,3 +522,4 @@ impl Solution { + diff --git "a/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" "b/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" index 8c85985fba..4ca7a3710b 100644 --- "a/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" +++ "b/problems/0070.\347\210\254\346\245\274\346\242\257\345\256\214\345\205\250\350\203\214\345\214\205\347\211\210\346\234\254.md" @@ -127,8 +127,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java class Solution { public int climbStairs(int n) { @@ -148,7 +148,7 @@ class Solution { } ``` -Python3: +### Python3: ```python @@ -166,8 +166,8 @@ class Solution: return dp[n] ``` +### Go: -Go: ```go func climbStairs(n int) int { //定义 @@ -189,7 +189,8 @@ func climbStairs(n int) int { } ``` -JavaScript: +### JavaScript: + ```javascript var climbStairs = function(n) { const dp = new Array(n + 1).fill(0); @@ -206,7 +207,7 @@ var climbStairs = function(n) { }; ``` -TypeScript: +### TypeScript: ```typescript function climbStairs(n: number): number { @@ -226,7 +227,7 @@ function climbStairs(n: number): number { }; ``` -Rust: +### Rust: ```rust impl Solution { @@ -250,4 +251,3 @@ impl Solution { - From 86f794b11814568adac618f462076ad6b0d8edde Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 14:58:05 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200746.=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=9C=80=E5=B0=8F=E8=8A=B1=E8=B4=B9=E7=88=AC=E6=A5=BC?= =?UTF-8?q?=E6=A2=AF=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\261\350\264\271\347\210\254\346\245\274\346\242\257.md" | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git "a/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" "b/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" index 9eaaa4e9fe..6fb518c371 100644 --- "a/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" +++ "b/problems/0746.\344\275\277\347\224\250\346\234\200\345\260\217\350\212\261\350\264\271\347\210\254\346\245\274\346\242\257.md" @@ -37,9 +37,9 @@ * cost[i] 将会是一个整型数据,范围为 [0, 999] 。 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划开更了!| LeetCode:746. 使用最小花费爬楼梯](https://www.bilibili.com/video/BV16G411c7yZ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)::[动态规划开更了!| LeetCode:746. 使用最小花费爬楼梯](https://www.bilibili.com/video/BV16G411c7yZ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ----------- @@ -523,3 +523,4 @@ public class Solution + From 0e3500ed1c7b0d6db94d33b6d5db2a39424ac94b Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:01:47 +0800 Subject: [PATCH 05/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=A7=84=E5=88=92=20=E5=91=A8=E6=9C=AB=E6=80=BB=E7=BB=93=20?= =?UTF-8?q?=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" | 1 + ...0\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" | 1 + ...0\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" | 1 + ...0\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" | 1 + 4 files changed, 4 insertions(+) diff --git "a/problems/\345\221\250\346\200\273\347\273\223/20210107\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" "b/problems/\345\221\250\346\200\273\347\273\223/20210107\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" index b4baa4adb0..831ce348a1 100644 --- "a/problems/\345\221\250\346\200\273\347\273\223/20210107\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" +++ "b/problems/\345\221\250\346\200\273\347\273\223/20210107\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" @@ -1,3 +1,4 @@ +# 本周小结!(动态规划系列一) 这周我们正式开始动态规划的学习! diff --git "a/problems/\345\221\250\346\200\273\347\273\223/20210114\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" "b/problems/\345\221\250\346\200\273\347\273\223/20210114\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" index a77efa2fd2..71cb49a9db 100644 --- "a/problems/\345\221\250\346\200\273\347\273\223/20210114\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" +++ "b/problems/\345\221\250\346\200\273\347\273\223/20210114\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" @@ -1,3 +1,4 @@ +# 本周小结!(动态规划系列二) ## 周一 diff --git "a/problems/\345\221\250\346\200\273\347\273\223/20210225\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" "b/problems/\345\221\250\346\200\273\347\273\223/20210225\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" index 8fd292ed9a..e74dd6bea8 100644 --- "a/problems/\345\221\250\346\200\273\347\273\223/20210225\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" +++ "b/problems/\345\221\250\346\200\273\347\273\223/20210225\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" @@ -1,3 +1,4 @@ +# 本周小结!(动态规划系列六) 本周我们主要讲解了打家劫舍系列,这个系列也是dp解决的经典问题,那么来看看我们收获了哪些呢,一起来回顾一下吧。 diff --git "a/problems/\345\221\250\346\200\273\347\273\223/20210304\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" "b/problems/\345\221\250\346\200\273\347\273\223/20210304\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" index b814e1b39e..ec442a3979 100644 --- "a/problems/\345\221\250\346\200\273\347\273\223/20210304\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" +++ "b/problems/\345\221\250\346\200\273\347\273\223/20210304\345\212\250\350\247\204\345\221\250\346\234\253\346\200\273\347\273\223.md" @@ -1,3 +1,4 @@ +# 本周小结!(动态规划系列七) 本周的主题就是股票系列,来一起回顾一下吧 From 126aaac841078b436f9d0e878a1bef1c0f8aeee1 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:06:55 +0800 Subject: [PATCH 06/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E8=83=8C=E5=8C=85?= =?UTF-8?q?=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=20=E6=8E=92=E7=89=88?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...47\241\20001\350\203\214\345\214\205-1.md" | 22 +++++++++---------- ...47\241\20001\350\203\214\345\214\205-2.md" | 14 +++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git "a/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-1.md" "b/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-1.md" index bd3191dca0..7511ac8715 100644 --- "a/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-1.md" +++ "b/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-1.md" @@ -8,8 +8,11 @@ # 动态规划:01背包理论基础 +## 算法公开课 -**《代码随想录》算法视频公开课:[带你学透0-1背包问题!](https://www.bilibili.com/video/BV1cg411g7Y6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[带你学透0-1背包问题!](https://www.bilibili.com/video/BV1cg411g7Y6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + +## 思路 这周我们正式开始讲解背包问题! @@ -37,7 +40,7 @@ leetcode上没有纯01背包的问题,都是01背包应用方面的题目, 之前可能有些录友已经可以熟练写出背包了,但只要把这个文章仔细看完,相信你会意外收获! -## 01 背包 +### 01 背包 有n件物品和一个最多能背重量为w 的背包。第i件物品的重量是weight[i],得到的价值是value[i] 。**每件物品只能用一次**,求解将哪些物品装入背包里物品价值总和最大。 @@ -67,7 +70,7 @@ leetcode上没有纯01背包的问题,都是01背包应用方面的题目, 以下讲解和图示中出现的数字都是以这个例子为例。 -## 二维dp数组01背包 +### 二维dp数组01背包 依然动规五部曲分析一波。 @@ -226,9 +229,6 @@ dp[i-1][j]和dp[i - 1][j - weight[i]] 都在dp[i][j]的左上角方向(包括 主要就是自己没有动手推导一下dp数组的演变过程,如果推导明白了,代码写出来就算有问题,只要把dp数组打印出来,对比一下和自己推导的有什么差异,很快就可以发现问题了。 - -## 完整c++测试代码 - ```cpp void test_2_wei_bag_problem1() { vector weight = {1, 3, 4}; @@ -275,7 +275,7 @@ int main() { ## 其他语言版本 -### java +### Java ```java public class BagProblem { @@ -396,7 +396,8 @@ public class BagProblem { ``` -### python +### Python + 无参数版 ```python def test_2_wei_bag_problem1(): @@ -456,8 +457,7 @@ if __name__ == "__main__": ``` - -### go +### Go ```go func test_2_wei_bag_problem1(weight, value []int, bagweight int) int { @@ -498,7 +498,7 @@ func main() { } ``` -### javascript +### Javascript ```js function testWeightBagProblem (weight, value, size) { diff --git "a/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-2.md" "b/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-2.md" index d481e044c5..019947e536 100644 --- "a/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-2.md" +++ "b/problems/\350\203\214\345\214\205\347\220\206\350\256\272\345\237\272\347\241\20001\350\203\214\345\214\205-2.md" @@ -3,10 +3,13 @@

参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!

- # 动态规划:01背包理论基础(滚动数组) -**《代码随想录》算法视频公开课:[带你学透0-1背包问题!(滚动数组)](https://www.bilibili.com/video/BV1BU4y177kY/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +## 算法公开课 + +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[带你学透0-1背包问题!(滚动数组)](https://www.bilibili.com/video/BV1BU4y177kY/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + +## 思路 昨天[动态规划:关于01背包问题,你该了解这些!](https://programmercarl.com/背包理论基础01背包-1.html)中是用二维dp数组来讲解01背包。 @@ -29,7 +32,7 @@ 问背包能背的物品最大价值是多少? -## 一维dp数组(滚动数组) +### 一维dp数组(滚动数组) 对于背包问题其实状态都是可以压缩的。 @@ -154,8 +157,6 @@ dp[1] = dp[1 - weight[0]] + value[0] = 15 -## 一维dp01背包完整C++测试代码 - ```CPP void test_1_wei_bag_problem() { vector weight = {1, 3, 4}; @@ -318,7 +319,7 @@ func main() { } ``` -### javaScript +### JavaScript ```js @@ -459,3 +460,4 @@ fn test_wei_bag_problem2() { + From fc19feb04939aee16372c6a6880a4a0ee3373110 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:13:26 +0800 Subject: [PATCH 07/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200416.=E5=88=86?= =?UTF-8?q?=E5=89=B2=E7=AD=89=E5=92=8C=E8=87=AA=E5=B7=B1=200474.=E4=B8=80?= =?UTF-8?q?=E5=92=8C=E9=9B=B6=200494.=E7=9B=AE=E6=A0=87=E5=92=8C=201049.?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E5=9D=97=E7=9F=B3=E5=A4=B4=E7=9A=84?= =?UTF-8?q?=E9=87=8D=E9=87=8FII=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\255\211\345\222\214\345\255\220\351\233\206.md" | 13 +++++++------ .../0474.\344\270\200\345\222\214\351\233\266.md" | 5 +++-- .../0494.\347\233\256\346\240\207\345\222\214.md" | 11 +++++------ ...44\264\347\232\204\351\207\215\351\207\217II.md" | 13 +++++++------ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git "a/problems/0416.\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.md" "b/problems/0416.\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.md" index a886b99a6d..0657c010bb 100644 --- "a/problems/0416.\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.md" +++ "b/problems/0416.\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.md" @@ -30,9 +30,9 @@ * 1 <= nums.length <= 200 * 1 <= nums[i] <= 100 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划之背包问题,这个包能装满吗?| LeetCode:416.分割等和子集](https://www.bilibili.com/video/BV1rt4y1N7jE/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之背包问题,这个包能装满吗?| LeetCode:416.分割等和子集](https://www.bilibili.com/video/BV1rt4y1N7jE/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -53,7 +53,7 @@ * [动态规划:关于01背包问题,你该了解这些!](https://programmercarl.com/背包理论基础01背包-1.html) * [动态规划:关于01背包问题,你该了解这些!(滚动数组)](https://programmercarl.com/背包理论基础01背包-2.html) -## 01背包问题 +### 01背包问题 背包问题,大家都知道,有N件物品和一个最多能背重量为W 的背包。第i件物品的重量是weight[i],得到的价值是value[i] 。每件物品只能用一次,求解将哪些物品装入背包里物品价值总和最大。 @@ -479,7 +479,7 @@ func canPartition(nums []int) bool { } ``` -### javaScript: +### JavaScript: ```js var canPartition = function(nums) { @@ -499,7 +499,7 @@ var canPartition = function(nums) { ``` -### Rust +### Rust: ```Rust impl Solution { @@ -681,7 +681,7 @@ function canPartition(nums: number[]): boolean { }; ``` -### Scala +### Scala: 滚动数组: ```scala @@ -730,3 +730,4 @@ object Solution { + diff --git "a/problems/0474.\344\270\200\345\222\214\351\233\266.md" "b/problems/0474.\344\270\200\345\222\214\351\233\266.md" index 7c1206ef35..8f6197ac5c 100644 --- "a/problems/0474.\344\270\200\345\222\214\351\233\266.md" +++ "b/problems/0474.\344\270\200\345\222\214\351\233\266.md" @@ -34,9 +34,9 @@ * strs[i] 仅由 '0' 和 '1' 组成 * 1 <= m, n <= 100 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[装满这个背包最多用多少个物品?| LeetCode:474.一和零](https://www.bilibili.com/video/BV1rW4y1x7ZQ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[装满这个背包最多用多少个物品?| LeetCode:474.一和零](https://www.bilibili.com/video/BV1rW4y1x7ZQ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -538,3 +538,4 @@ impl Solution { + diff --git "a/problems/0494.\347\233\256\346\240\207\345\222\214.md" "b/problems/0494.\347\233\256\346\240\207\345\222\214.md" index 1902d5ed44..4a4e966c14 100644 --- "a/problems/0494.\347\233\256\346\240\207\345\222\214.md" +++ "b/problems/0494.\347\233\256\346\240\207\345\222\214.md" @@ -37,9 +37,9 @@ * 初始的数组的和不会超过 1000 。 * 保证返回的最终结果能被 32 位整数存下。 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[装满背包有多少种方法?| LeetCode:494.目标和](https://www.bilibili.com/video/BV1o8411j73x/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[装满背包有多少种方法?| LeetCode:494.目标和](https://www.bilibili.com/video/BV1o8411j73x/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -67,7 +67,7 @@ target是固定的,sum是固定的,left就可以求出来。 此时问题就是在集合nums中找出和为left的组合。 -## 回溯算法 +### 回溯算法 在回溯算法系列中,一起学过这道题目[回溯算法:39. 组合总和](https://programmercarl.com/0039.组合总和.html)的录友应该感觉很熟悉,这不就是组合总和问题么? @@ -118,7 +118,7 @@ public: 也可以使用记忆化回溯,但这里我就不在回溯上下功夫了,直接看动规吧 -## 动态规划 +### 动态规划 如何转化为01背包问题呢。 @@ -519,8 +519,6 @@ const findTargetSumWays = (nums, target) => { ### TypeScript -TypeScript: - ```ts function findTargetSumWays(nums: number[], target: number): number { // 把数组分成两个组合left, right.left + right = sum, left - right = target. @@ -590,3 +588,4 @@ impl Solution { + diff --git "a/problems/1049.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217II.md" "b/problems/1049.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217II.md" index 932029ab7a..cc66131734 100644 --- "a/problems/1049.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217II.md" +++ "b/problems/1049.\346\234\200\345\220\216\344\270\200\345\235\227\347\237\263\345\244\264\347\232\204\351\207\215\351\207\217II.md" @@ -35,9 +35,9 @@ * 1 <= stones.length <= 30 * 1 <= stones[i] <= 1000 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[这个背包最多能装多少?LeetCode:1049.最后一块石头的重量II](https://www.bilibili.com/video/BV14M411C7oV/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[这个背包最多能装多少?LeetCode:1049.最后一块石头的重量II](https://www.bilibili.com/video/BV14M411C7oV/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -341,7 +341,7 @@ func max(a, b int) int { } ``` -### JavaScript +### JavaScript: ```javascript /** @@ -364,7 +364,7 @@ var lastStoneWeightII = function (stones) { }; ``` -### C +### C: ```c #define MAX(a, b) (((a) > (b)) ? (a) : (b)) @@ -413,7 +413,7 @@ function lastStoneWeightII(stones: number[]): number { }; ``` -### Scala +### Scala: 滚动数组: ```scala @@ -455,7 +455,7 @@ object Solution { } ``` -### Rust +### Rust: ```rust impl Solution { @@ -477,3 +477,4 @@ impl Solution { + From 7ac217942fea957c2d8cfb579e81d80bbd590499 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:28:27 +0800 Subject: [PATCH 08/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E8=83=8C=E5=8C=85=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=200139.?= =?UTF-8?q?=E5=8D=95=E8=AF=8D=E6=8B=86=E5=88=86=200279.=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E5=B9=B3=E6=96=B9=E6=95=B0=200322.=E9=9B=B6=E9=92=B1=E5=85=91?= =?UTF-8?q?=E6=8D=A2=200377.=E7=BB=84=E5=90=88=E6=80=BB=E5=92=8CIV=200518.?= =?UTF-8?q?=E9=9B=B6=E9=92=B1=E5=85=91=E6=8D=A2II=20=E5=A4=9A=E9=87=8D?= =?UTF-8?q?=E8=83=8C=E5=8C=85=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80=20?= =?UTF-8?q?=E8=83=8C=E5=8C=85=E6=80=BB=E7=BB=93=E7=AF=87=20=E6=8E=92?= =?UTF-8?q?=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\350\257\215\346\213\206\345\210\206.md" | 23 ++++++++------- ...50\345\271\263\346\226\271\346\225\260.md" | 21 +++++++------- ...66\351\222\261\345\205\221\346\215\242.md" | 20 +++++++------ ...10\346\200\273\345\222\214\342\205\243.md" | 20 +++++++------ ...\351\222\261\345\205\221\346\215\242II.md" | 22 +++++++------- ...05\346\200\273\347\273\223\347\257\207.md" | 1 + ...32\351\207\215\350\203\214\345\214\205.md" | 10 +++---- ...14\345\205\250\350\203\214\345\214\205.md" | 29 ++++++++++--------- 8 files changed, 80 insertions(+), 66 deletions(-) diff --git "a/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" "b/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" index 0d88ba3681..d93288ae5a 100644 --- "a/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" +++ "b/problems/0139.\345\215\225\350\257\215\346\213\206\345\210\206.md" @@ -33,9 +33,9 @@ * 输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] * 输出: false -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[你的背包如何装满?| LeetCode:139.单词拆分](https://www.bilibili.com/video/BV1pd4y147Rh/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[你的背包如何装满?| LeetCode:139.单词拆分](https://www.bilibili.com/video/BV1pd4y147Rh/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -123,7 +123,7 @@ public: **这个代码就可以AC了,当然回溯算法不是本题的主菜,背包才是!** -## 背包问题 +### 背包问题 单词就是物品,字符串s就是背包,单词能否组成字符串s,就是问物品能不能把背包装满。 @@ -239,7 +239,7 @@ public: } }; -``` +``` 使用用例:s = "applepenapple", wordDict = ["apple", "pen"],对应的dp数组状态如下: @@ -259,8 +259,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java class Solution { public boolean wordBreak(String s, List wordDict) { @@ -335,7 +335,7 @@ class Solution { } ``` -Python: +### Python: 回溯 ```python @@ -397,7 +397,8 @@ class Solution: -Go: +### Go: + ```Go func wordBreak(s string,wordDict []string) bool { wordDictSet := make(map[string]bool) @@ -433,7 +434,8 @@ func wordBreak(s string, wordDict []string) bool { } ``` -Javascript: +### JavaScript: + ```javascript const wordBreak = (s, wordDict) => { @@ -454,7 +456,7 @@ const wordBreak = (s, wordDict) => { } ``` -TypeScript: +### TypeScript: > 动态规划 @@ -496,7 +498,7 @@ function wordBreak(s: string, wordDict: string[]): boolean { }; ``` -Rust: +### Rust: ```rust impl Solution { @@ -519,3 +521,4 @@ impl Solution { + diff --git "a/problems/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.md" "b/problems/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.md" index 70ab8649fd..a0c138ee80 100644 --- "a/problems/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.md" +++ "b/problems/0279.\345\256\214\345\205\250\345\271\263\346\226\271\346\225\260.md" @@ -28,9 +28,9 @@ 提示: * 1 <= n <= 10^4 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[换汤不换药!| LeetCode:279.完全平方数](https://www.bilibili.com/video/BV12P411T7Br/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[换汤不换药!| LeetCode:279.完全平方数](https://www.bilibili.com/video/BV12P411T7Br/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -106,8 +106,6 @@ dp[5] = min(dp[4] + 1, dp[1] + 1) = 2 最后的dp[n]为最终结果。 -## C++代码 - 以上动规五部曲分析完毕C++代码如下: ```CPP @@ -165,8 +163,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java class Solution { // 版本一,先遍历物品, 再遍历背包 @@ -219,7 +217,7 @@ class Solution { } ``` -Python: +### Python: 先遍历物品, 再遍历背包 ```python @@ -276,7 +274,8 @@ class Solution: ``` -Go: +### Go: + ```go // 版本一,先遍历物品, 再遍历背包 func numSquares1(n int) int { @@ -327,7 +326,8 @@ func min(a, b int) int { } ``` -Javascript: +### Javascript: + ```Javascript // 先遍历物品,再遍历背包 var numSquares1 = function(n) { @@ -357,7 +357,7 @@ var numSquares2 = function(n) { }; ``` -TypeScript: +### TypeScript: ```typescript // 先遍历物品 @@ -389,7 +389,7 @@ function numSquares(n: number): number { }; ``` -Rust: +### Rust: ```rust // 先遍历背包 @@ -439,3 +439,4 @@ impl Solution { + diff --git "a/problems/0322.\351\233\266\351\222\261\345\205\221\346\215\242.md" "b/problems/0322.\351\233\266\351\222\261\345\205\221\346\215\242.md" index 1f3f4df27f..f32fd13e23 100644 --- "a/problems/0322.\351\233\266\351\222\261\345\205\221\346\215\242.md" +++ "b/problems/0322.\351\233\266\351\222\261\345\205\221\346\215\242.md" @@ -39,9 +39,9 @@ * 1 <= coins[i] <= 2^31 - 1 * 0 <= amount <= 10^4 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[装满背包最少的物品件数是多少?| LeetCode:322.零钱兑换](https://www.bilibili.com/video/BV14K411R7yv/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[装满背包最少的物品件数是多少?| LeetCode:322.零钱兑换](https://www.bilibili.com/video/BV14K411R7yv/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 @@ -110,7 +110,6 @@ dp[0] = 0; dp[amount]为最终结果。 -## C++代码 以上分析完毕,C++ 代码如下: ```CPP @@ -187,8 +186,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java class Solution { public int coinChange(int[] coins, int amount) { @@ -215,7 +214,7 @@ class Solution { } ``` -Python: +### Python: 先遍历物品 后遍历背包 @@ -288,7 +287,8 @@ class Solution: ``` -Go: +### Go: + ```go // 版本一, 先遍历物品,再遍历背包 func coinChange1(coins []int, amount int) int { @@ -352,7 +352,7 @@ func min(a, b int) int { ``` -Rust: +### Rust: ```rust // 遍历物品 @@ -398,7 +398,8 @@ impl Solution { } ``` -Javascript: +### Javascript: + ```javascript // 遍历物品 const coinChange = (coins, amount) => { @@ -435,7 +436,7 @@ var coinChange = function(coins, amount) { } ``` -TypeScript: +### TypeScript: ```typescript // 遍历物品 @@ -473,3 +474,4 @@ function coinChange(coins: number[], amount: number): number { + diff --git "a/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" "b/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" index bd43d52657..d9699c5407 100644 --- "a/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" +++ "b/problems/0377.\347\273\204\345\220\210\346\200\273\345\222\214\342\205\243.md" @@ -31,9 +31,9 @@ 因此输出为 7。 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[装满背包有几种方法?求排列数?| LeetCode:377.组合总和IV](https://www.bilibili.com/video/BV1V14y1n7B6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[装满背包有几种方法?求排列数?| LeetCode:377.组合总和IV](https://www.bilibili.com/video/BV1V14y1n7B6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -154,8 +154,7 @@ C++测试用例有两个数相加超过int的数据,所以需要在if里加上 ## 其他语言版本 - -Java: +### Java: ```Java class Solution { @@ -174,7 +173,7 @@ class Solution { } ``` -Python: +### Python: 卡哥版 @@ -207,7 +206,8 @@ class Solution: ``` -Go: +### Go: + ```go func combinationSum4(nums []int, target int) int { //定义dp数组 @@ -226,7 +226,8 @@ func combinationSum4(nums []int, target int) int { } ``` -Javascript: +### Javascript: + ```javascript const combinationSum4 = (nums, target) => { @@ -245,7 +246,7 @@ const combinationSum4 = (nums, target) => { }; ``` -TypeScript: +### TypeScript: ```typescript function combinationSum4(nums: number[], target: number): number { @@ -264,7 +265,7 @@ function combinationSum4(nums: number[], target: number): number { }; ``` -Rust +### Rust: ```Rust impl Solution { @@ -289,3 +290,4 @@ impl Solution { + diff --git "a/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" "b/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" index 8da351148b..7c9f0fcefb 100644 --- "a/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" +++ "b/problems/0518.\351\233\266\351\222\261\345\205\221\346\215\242II.md" @@ -41,9 +41,9 @@ * 硬币种类不超过 500 种 * 结果符合 32 位符号整数 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[装满背包有多少种方法?组合与排列有讲究!| LeetCode:518.零钱兑换II](https://www.bilibili.com/video/BV1KM411k75j/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[装满背包有多少种方法?组合与排列有讲究!| LeetCode:518.零钱兑换II](https://www.bilibili.com/video/BV1KM411k75j/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 @@ -202,8 +202,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java class Solution { public int change(int amount, int[] coins) { @@ -242,7 +242,7 @@ class Solution { } ``` -Python: +### Python: ```python @@ -260,7 +260,8 @@ class Solution: -Go: +### Go: + ```go func change(amount int, coins []int) int { // 定义dp数组 @@ -280,7 +281,8 @@ func change(amount int, coins []int) int { } ``` -Rust: +### Rust: + ```rust impl Solution { pub fn change(amount: i32, coins: Vec) -> i32 { @@ -297,7 +299,8 @@ impl Solution { } ``` -Javascript: +### Javascript: + ```javascript const change = (amount, coins) => { let dp = Array(amount + 1).fill(0); @@ -313,7 +316,7 @@ const change = (amount, coins) => { } ``` -TypeScript: +### TypeScript: ```typescript function change(amount: number, coins: number[]): number { @@ -328,7 +331,7 @@ function change(amount: number, coins: number[]): number { }; ``` -Scala: +### Scala: ```scala object Solution { @@ -349,4 +352,3 @@ object Solution { - diff --git "a/problems/\350\203\214\345\214\205\346\200\273\347\273\223\347\257\207.md" "b/problems/\350\203\214\345\214\205\346\200\273\347\273\223\347\257\207.md" index c4e8cd9cff..9be93096fd 100644 --- "a/problems/\350\203\214\345\214\205\346\200\273\347\273\223\347\257\207.md" +++ "b/problems/\350\203\214\345\214\205\346\200\273\347\273\223\347\257\207.md" @@ -106,3 +106,4 @@ + diff --git "a/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\244\232\351\207\215\350\203\214\345\214\205.md" "b/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\244\232\351\207\215\350\203\214\345\214\205.md" index 1a856bf5fa..50c2e5bf8c 100644 --- "a/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\244\232\351\207\215\350\203\214\345\214\205.md" +++ "b/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\244\232\351\207\215\350\203\214\345\214\205.md" @@ -144,8 +144,7 @@ int main() { ## 其他语言版本 - -Java: +### Java: ```Java public void testMultiPack1(){ @@ -192,7 +191,7 @@ public void testMultiPack2(){ } ``` -Python: +### Python: 改变物品数量为01背包格式(无参版) ```python @@ -315,7 +314,7 @@ if __name__ == "__main__": test_multi_pack(weight, value, nums, bagWeight) ``` -Go: +### Go: ```go package theory @@ -406,7 +405,7 @@ func Test_multiplePack(t *testing.T) { PASS ``` -TypeScript: +### TypeScript: > 版本一(改变数据源): @@ -469,3 +468,4 @@ testMultiPack(); + diff --git "a/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\256\214\345\205\250\350\203\214\345\214\205.md" "b/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\256\214\345\205\250\350\203\214\345\214\205.md" index 088a3d50e9..ac4c4a1cbe 100644 --- "a/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\256\214\345\205\250\350\203\214\345\214\205.md" +++ "b/problems/\350\203\214\345\214\205\351\227\256\351\242\230\347\220\206\350\256\272\345\237\272\347\241\200\345\256\214\345\205\250\350\203\214\345\214\205.md" @@ -7,9 +7,13 @@ # 动态规划:完全背包理论基础 -**《代码随想录》算法视频公开课:[带你学透完全背包问题! ](https://www.bilibili.com/video/BV1uK411o7c9/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +## 算法公开课 -## 完全背包 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[带你学透完全背包问题! ](https://www.bilibili.com/video/BV1uK411o7c9/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 + +## 思路 + +### 完全背包 有N件物品和一个最多能背重量为W的背包。第i件物品的重量是weight[i],得到的价值是value[i] 。**每件物品都有无限个(也就是可以放入背包多次)**,求解将哪些物品装入背包里物品价值总和最大。 @@ -113,8 +117,6 @@ for(int j = 0; j <= bagWeight; j++) { // 遍历背包容量 } ``` -## C++测试代码 - 完整的C++测试代码如下: ```CPP @@ -181,7 +183,7 @@ int main() { ## 其他语言版本 -Java: +### Java: ```java //先遍历物品,再遍历背包 @@ -221,9 +223,7 @@ private static void testCompletePackAnotherWay(){ -Python: - - +### Python: 先遍历物品,再遍历背包(无参版) ```python @@ -299,7 +299,8 @@ if __name__ == "__main__": ``` -Go: +### Go: + ```go // test_CompletePack1 先遍历物品, 在遍历背包 @@ -352,7 +353,8 @@ func main() { fmt.Println(test_CompletePack2(weight, price, 4)) } ``` -Javascript: +### Javascript: + ```Javascript // 先遍历物品,再遍历背包容量 function test_completePack1() { @@ -385,7 +387,7 @@ function test_completePack2() { } ``` -TypeScript: +### TypeScript: ```typescript // 先遍历物品,再遍历背包容量 @@ -404,7 +406,7 @@ function test_CompletePack(): void { test_CompletePack(); ``` -Scala: +### Scala: ```scala // 先遍历物品,再遍历背包容量 @@ -426,7 +428,7 @@ object Solution { } ``` -Rust: +### Rust: ```rust impl Solution { @@ -468,3 +470,4 @@ fn test_complete_pack() { + From 89571ea8f867a22ca0ff69017ea8b741e965c3c4 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:33:10 +0800 Subject: [PATCH 09/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200198.=E6=89=93?= =?UTF-8?q?=E5=AE=B6=E5=8A=AB=E8=88=8D=200213.=E6=89=93=E5=AE=B6=E5=8A=AB?= =?UTF-8?q?=E8=88=8DII=200337.=E6=89=93=E5=AE=B6=E5=8A=AB=E8=88=8DIII=20?= =?UTF-8?q?=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...223\345\256\266\345\212\253\350\210\215.md" | 18 +++++++++--------- ...3\345\256\266\345\212\253\350\210\215II.md" | 18 ++++++++++-------- ...\345\256\266\345\212\253\350\210\215III.md" | 5 +++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git "a/problems/0198.\346\211\223\345\256\266\345\212\253\350\210\215.md" "b/problems/0198.\346\211\223\345\256\266\345\212\253\350\210\215.md" index 80902559a6..a7bc4c998e 100644 --- "a/problems/0198.\346\211\223\345\256\266\345\212\253\350\210\215.md" +++ "b/problems/0198.\346\211\223\345\256\266\345\212\253\350\210\215.md" @@ -31,9 +31,9 @@ * 0 <= nums.length <= 100 * 0 <= nums[i] <= 400 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划,偷不偷这个房间呢?| LeetCode:198.打家劫舍](https://www.bilibili.com/video/BV1Te411N7SX),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,偷不偷这个房间呢?| LeetCode:198.打家劫舍](https://www.bilibili.com/video/BV1Te411N7SX),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -121,8 +121,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java // 动态规划 class Solution { @@ -194,7 +194,7 @@ class Solution { } ``` -Python: +### Python: 1维DP ```python @@ -255,7 +255,8 @@ class Solution: ``` -Go: +### Go: + ```Go func rob(nums []int) int { n := len(nums) @@ -275,7 +276,7 @@ func max(a, b int) int { } ``` -JavaScript: +### JavaScript: ```javascript const rob = nums => { @@ -291,7 +292,7 @@ const rob = nums => { }; ``` -TypeScript: +### TypeScript: ```typescript function rob(nums: number[]): number { @@ -314,7 +315,7 @@ function rob(nums: number[]): number { }; ``` -Rust: +### Rust: ```rust impl Solution { @@ -338,4 +339,3 @@ impl Solution { - diff --git "a/problems/0213.\346\211\223\345\256\266\345\212\253\350\210\215II.md" "b/problems/0213.\346\211\223\345\256\266\345\212\253\350\210\215II.md" index ee62b5745e..cd9d596d70 100644 --- "a/problems/0213.\346\211\223\345\256\266\345\212\253\350\210\215II.md" +++ "b/problems/0213.\346\211\223\345\256\266\345\212\253\350\210\215II.md" @@ -31,9 +31,9 @@ * 1 <= nums.length <= 100 * 0 <= nums[i] <= 1000 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划,房间连成环了那还偷不偷呢?| LeetCode:213.打家劫舍II](https://www.bilibili.com/video/BV1oM411B7xq),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,房间连成环了那还偷不偷呢?| LeetCode:213.打家劫舍II](https://www.bilibili.com/video/BV1oM411B7xq),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -104,8 +104,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java class Solution { public int rob(int[] nums) { @@ -129,7 +129,7 @@ class Solution { } ``` -Python: +### Python: ```Python class Solution: @@ -219,7 +219,7 @@ class Solution: ``` -Go: +### Go: ```go // 打家劫舍Ⅱ 动态规划 @@ -257,7 +257,8 @@ func max(a, b int) int { } ``` -javascipt: +### JavaScript: + ```javascript var rob = function(nums) { const n = nums.length @@ -279,7 +280,7 @@ const robRange = (nums, start, end) => { return dp[end] } ``` -TypeScript: +### TypeScript: ```typescript function rob(nums: number[]): number { @@ -301,7 +302,7 @@ function robRange(nums: number[], start: number, end: number): number { } ``` -Rust: +### Rust: ```rust impl Solution { @@ -336,3 +337,4 @@ impl Solution { + diff --git "a/problems/0337.\346\211\223\345\256\266\345\212\253\350\210\215III.md" "b/problems/0337.\346\211\223\345\256\266\345\212\253\350\210\215III.md" index 1708b7a1e8..96d487e215 100644 --- "a/problems/0337.\346\211\223\345\256\266\345\212\253\350\210\215III.md" +++ "b/problems/0337.\346\211\223\345\256\266\345\212\253\350\210\215III.md" @@ -16,9 +16,9 @@ ![337.打家劫舍III](https://code-thinking-1253855093.file.myqcloud.com/pics/20210223173849619.png) -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划,房间连成树了,偷不偷呢?| LeetCode:337.打家劫舍3](https://www.bilibili.com/video/BV1H24y1Q7sY),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,房间连成树了,偷不偷呢?| LeetCode:337.打家劫舍3](https://www.bilibili.com/video/BV1H24y1Q7sY),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -523,3 +523,4 @@ impl Solution { + From 6b322684a4ebc096d71d36846496501f6e3ffefa Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:55:12 +0800 Subject: [PATCH 10/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E4=B9=B0=E5=8D=96?= =?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?=E7=B3=BB=E5=88=97=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00\344\275\263\346\227\266\346\234\272.md" | 22 +++++++++---------- ...01\350\247\204\345\210\222\357\274\211.md" | 21 +++++++++--------- ...344\275\263\346\227\266\346\234\272III.md" | 17 +++++++------- ...\344\275\263\346\227\266\346\234\272IV.md" | 17 +++++++------- ...53\345\206\267\345\206\273\346\234\237.md" | 19 +++++++++------- ...01\350\247\204\345\210\222\357\274\211.md" | 21 ++++++++++-------- ...30\346\200\273\347\273\223\347\257\207.md" | 13 +---------- 7 files changed, 63 insertions(+), 67 deletions(-) diff --git "a/problems/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.md" "b/problems/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.md" index 0630515662..cbdf40e85c 100644 --- "a/problems/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.md" +++ "b/problems/0121.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.md" @@ -24,11 +24,9 @@ * 输出:0 解释:在这种情况下, 没有交易完成, 所以最大利润为 0。 -# 算法公开课 - -**《代码随想录》算法视频公开课:[动态规划之 LeetCode:121.买卖股票的最佳时机1](https://www.bilibili.com/video/BV1Xe4y1u77q),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 - +## 算法公开课 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之 LeetCode:121.买卖股票的最佳时机1](https://www.bilibili.com/video/BV1Xe4y1u77q),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -202,7 +200,7 @@ public: ## 其他语言版本 -Java: +### Java: > 贪心法: @@ -294,8 +292,7 @@ class Solution { ``` - -Python: +### Python: > 贪心法: ```python @@ -351,7 +348,8 @@ class Solution: return dp1 ``` -Go: +### Go: + > 贪心法: ```Go func maxProfit(prices []int) int { @@ -418,7 +416,7 @@ func max(a, b int) int { } ``` -JavaScript: +### JavaScript: > 动态规划 @@ -454,7 +452,7 @@ var maxProfit = function(prices) { }; ``` -TypeScript: +### TypeScript: > 贪心法 @@ -492,7 +490,7 @@ function maxProfit(prices: number[]): number { }; ``` -C#: +### C#: > 贪心法 @@ -533,7 +531,7 @@ public class Solution } ``` -Rust: +### Rust: > 贪心 diff --git "a/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" "b/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" index 02f8d287d0..6e08b57c1d 100644 --- "a/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" +++ "b/problems/0122.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272II\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" @@ -34,9 +34,9 @@ * 1 <= prices.length <= 3 * 10 ^ 4 * 0 <= prices[i] <= 10 ^ 4 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划,股票问题第二弹 | LeetCode:122.买卖股票的最佳时机II](https://www.bilibili.com/video/BV1D24y1Q7Ls),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,股票问题第二弹 | LeetCode:122.买卖股票的最佳时机II](https://www.bilibili.com/video/BV1D24y1Q7Ls),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -133,8 +133,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java // 动态规划 class Solution @@ -191,7 +191,7 @@ class Solution { } ``` -Python: +### Python: > 版本一: ```python @@ -221,7 +221,8 @@ class Solution: return dp[(length-1) % 2][1] ``` -Go: +### Go: + ```go // 买卖股票的最佳时机Ⅱ 动态规划 // 时间复杂度:O(n) 空间复杂度:O(n) @@ -250,7 +251,8 @@ func max(a, b int) int { } ``` -Javascript: +### JavaScript: + ```javascript // 方法一:动态规划(dp 数组) const maxProfit = (prices) => { @@ -290,7 +292,7 @@ const maxProfit = (prices) => { } ``` -TypeScript: +### TypeScript: > 动态规划 @@ -326,7 +328,7 @@ function maxProfit(prices: number[]): number { }; ``` -C#: +### C#: > 贪心法 @@ -363,7 +365,7 @@ public class Solution } ``` -Rust: +### Rust: > 贪心 @@ -414,4 +416,3 @@ impl Solution { - diff --git "a/problems/0123.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272III.md" "b/problems/0123.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272III.md" index a646b7d517..72dd90426c 100644 --- "a/problems/0123.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272III.md" +++ "b/problems/0123.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272III.md" @@ -39,9 +39,9 @@ * 1 <= prices.length <= 10^5 * 0 <= prices[i] <= 10^5 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划,股票至多买卖两次,怎么求? | LeetCode:123.买卖股票最佳时机III](https://www.bilibili.com/video/BV1WG411K7AR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,股票至多买卖两次,怎么求? | LeetCode:123.买卖股票最佳时机III](https://www.bilibili.com/video/BV1WG411K7AR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -221,7 +221,7 @@ public: ## 其他语言版本 -Java: +### Java: ```java // 版本一 @@ -277,7 +277,7 @@ class Solution { } ``` -Python: +### Python: > 版本一: ```python @@ -314,7 +314,7 @@ class Solution: return dp[4] ``` -Go: +### Go: ```go func maxProfit(prices []int) int { @@ -344,7 +344,7 @@ func max(a, b int) int { } ``` -JavaScript: +### JavaScript: > 版本一: @@ -383,7 +383,7 @@ const maxProfit = prices => { }; ``` -TypeScript: +### TypeScript: > 版本一 @@ -413,7 +413,7 @@ function maxProfit(prices: number[]): number { }; ``` -Rust: +### Rust: > 版本一 @@ -465,3 +465,4 @@ impl Solution { + diff --git "a/problems/0188.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272IV.md" "b/problems/0188.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272IV.md" index 773a910a23..d4dc769893 100644 --- "a/problems/0188.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272IV.md" +++ "b/problems/0188.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272IV.md" @@ -31,9 +31,9 @@ * 0 <= prices.length <= 1000 * 0 <= prices[i] <= 1000 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划来决定最佳时机,至多可以买卖K次!| LeetCode:188.买卖股票最佳时机4](https://www.bilibili.com/video/BV16M411U7XJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划来决定最佳时机,至多可以买卖K次!| LeetCode:188.买卖股票最佳时机4](https://www.bilibili.com/video/BV16M411U7XJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -173,7 +173,7 @@ public: ## 其他语言版本 -Java: +### Java: ```java // 版本一: 三维 dp数组 @@ -295,7 +295,7 @@ class Solution { } ``` -Python: +### Python: 版本一 @@ -329,7 +329,7 @@ class Solution: dp[j] = max(dp[j],dp[j-1]+prices[i]) return dp[2*k] ``` -Go: +### Go: 版本一: @@ -404,7 +404,7 @@ func max188(a, b int) int { } ``` -Javascript: +### JavaScript: ```javascript // 方法一:动态规划 @@ -454,7 +454,7 @@ var maxProfit = function(k, prices) { }; ``` -TypeScript: +### TypeScript: ```typescript function maxProfit(k: number, prices: number[]): number { @@ -474,7 +474,7 @@ function maxProfit(k: number, prices: number[]): number { }; ``` -Rust: +### Rust: ```rust impl Solution { @@ -529,3 +529,4 @@ impl Solution { + diff --git "a/problems/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.md" "b/problems/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.md" index cd71136ba6..f4093b67e6 100644 --- "a/problems/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.md" +++ "b/problems/0309.\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.md" @@ -20,9 +20,9 @@ * 输出: 3 * 解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出] -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划来决定最佳时机,这次有冷冻期!| LeetCode:309.买卖股票的最佳时机含冷冻期](https://www.bilibili.com/video/BV1rP4y1D7ku),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划来决定最佳时机,这次有冷冻期!| LeetCode:309.买卖股票的最佳时机含冷冻期](https://www.bilibili.com/video/BV1rP4y1D7ku),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -174,7 +174,7 @@ public: ## 其他语言版本 -Java: +### Java: ```java class Solution { @@ -273,8 +273,9 @@ class Solution { } ``` -Python: +### Python: 版本一 + ```python from typing import List @@ -319,7 +320,8 @@ class Solution: return max(dp[-1][1], dp[-1][2]) ``` -Go: +### Go: + ```go // 最佳买卖股票时机含冷冻期 动态规划 // 时间复杂度O(n) 空间复杂度O(n) @@ -355,7 +357,7 @@ func max(a, b int) int { } ``` -Javascript: +### Javascript: ```javascript const maxProfit = (prices) => { @@ -397,7 +399,7 @@ const maxProfit = (prices) => { }; ``` -TypeScript: +### TypeScript: > 版本一,与本文思路一致 @@ -455,7 +457,7 @@ function maxProfit(prices: number[]): number { }; ``` -Rust: +### Rust: ```rust impl Solution { @@ -484,3 +486,4 @@ impl Solution { + diff --git "a/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" "b/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" index 042de94718..7e8e3d7c61 100644 --- "a/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" +++ "b/problems/0714.\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271\357\274\210\345\212\250\346\200\201\350\247\204\345\210\222\357\274\211.md" @@ -32,9 +32,9 @@ * 0 < prices[i] < 50000. * 0 <= fee < 50000. -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划来决定最佳时机,这次含手续费!| LeetCode:714.买卖股票的最佳时机含手续费](https://www.bilibili.com/video/BV1z44y1Z7UR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划来决定最佳时机,这次含手续费!| LeetCode:714.买卖股票的最佳时机含手续费](https://www.bilibili.com/video/BV1z44y1Z7UR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -97,8 +97,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java /** * 卖出时支付手续费 @@ -173,9 +173,9 @@ class Solution { } } ``` -``` +### python + -Python: ```python class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: @@ -188,7 +188,8 @@ class Solution: return max(dp[-1][0], dp[-1][1]) ``` -Go: +### Go: + ```go // 买卖股票的最佳时机含手续费 动态规划 // 时间复杂度O(n) 空间复杂度O(n) @@ -211,7 +212,8 @@ func max(a, b int) int { } ``` -Javascript: +### Javascript: + ```javascript const maxProfit = (prices,fee) => { let dp = Array.from(Array(prices.length), () => Array(2).fill(0)); @@ -224,7 +226,7 @@ const maxProfit = (prices,fee) => { } ``` -TypeScript: +### TypeScript: ```typescript function maxProfit(prices: number[], fee: number): number { @@ -245,8 +247,9 @@ function maxProfit(prices: number[], fee: number): number { }; ``` -Rust: +### Rust: **贪心** + ```Rust impl Solution { pub fn max_profit(prices: Vec, fee: i32) -> i32 { diff --git "a/problems/\345\212\250\346\200\201\350\247\204\345\210\222-\350\202\241\347\245\250\351\227\256\351\242\230\346\200\273\347\273\223\347\257\207.md" "b/problems/\345\212\250\346\200\201\350\247\204\345\210\222-\350\202\241\347\245\250\351\227\256\351\242\230\346\200\273\347\273\223\347\257\207.md" index 2b04b7b085..4df21fb761 100644 --- "a/problems/\345\212\250\346\200\201\350\247\204\345\210\222-\350\202\241\347\245\250\351\227\256\351\242\230\346\200\273\347\273\223\347\257\207.md" +++ "b/problems/\345\212\250\346\200\201\350\247\204\345\210\222-\350\202\241\347\245\250\351\227\256\351\242\230\346\200\273\347\273\223\347\257\207.md" @@ -471,21 +471,10 @@ public: 「代码随想录」值得推荐给身边每一位学习算法的朋友同学们,关注后都会发现相见恨晚! -## 其他语言版本 - - -Java: - - -Python: - - -Go: - -

+ From 038d50957cff8e3e370a1812ff36afa5feb72945 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 15:58:53 +0800 Subject: [PATCH 11/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200674.=E6=9C=80?= =?UTF-8?q?=E9=95=BF=E8=BF=9E=E7=BB=AD=E9=80=92=E5=A2=9E=E5=BA=8F=E5=88=97?= =?UTF-8?q?=20=E6=8E=92=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...07\345\255\220\345\272\217\345\210\227.md" | 24 +++++++++---------- ...22\345\242\236\345\272\217\345\210\227.md" | 18 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git "a/problems/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.md" "b/problems/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.md" index c58c3bf6c4..11cf13d9c5 100644 --- "a/problems/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.md" +++ "b/problems/0300.\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.md" @@ -33,7 +33,7 @@ ## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划之子序列问题,元素不连续!| LeetCode:300.最长递增子序列](https://www.bilibili.com/video/BV1ng411J7xP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)::[动态规划之子序列问题,元素不连续!| LeetCode:300.最长递增子序列](https://www.bilibili.com/video/BV1ng411J7xP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -124,8 +124,8 @@ public: ## 其他语言版本 +### Java: -Java: ```Java class Solution { public int lengthOfLIS(int[] nums) { @@ -147,7 +147,7 @@ class Solution { } ``` -Python: +### Python: DP ```python @@ -189,7 +189,8 @@ class Solution: return len(tails) # 返回递增子序列的长度 ``` -Go: +### Go: + ```go // 动态规划求解 func lengthOfLIS(nums []int) int { @@ -248,7 +249,8 @@ func lengthOfLIS(nums []int ) int { } ``` -Javascript +### Javascript: + ```javascript const lengthOfLIS = (nums) => { let dp = Array(nums.length).fill(1); @@ -267,7 +269,7 @@ const lengthOfLIS = (nums) => { }; ``` -TypeScript +### TypeScript: ```typescript function lengthOfLIS(nums: number[]): number { @@ -288,7 +290,8 @@ function lengthOfLIS(nums: number[]): number { }; ``` -Rust: +### Rust: + ```rust pub fn length_of_lis(nums: Vec) -> i32 { let mut dp = vec![1; nums.len() + 1]; @@ -307,13 +310,8 @@ pub fn length_of_lis(nums: Vec) -> i32 { - - - - - -

+ diff --git "a/problems/0674.\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.md" "b/problems/0674.\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.md" index 8cc270ec64..0c5e64b34e 100644 --- "a/problems/0674.\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.md" +++ "b/problems/0674.\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.md" @@ -29,7 +29,7 @@ ## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划之子序列问题,重点在于连续!| LeetCode:674.最长连续递增序列](https://www.bilibili.com/video/BV1bD4y1778v),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之子序列问题,重点在于连续!| LeetCode:674.最长连续递增序列](https://www.bilibili.com/video/BV1bD4y1778v),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -157,8 +157,7 @@ public: ## 其他语言版本 - -Java: +### Java: > 动态规划: ```java @@ -207,7 +206,7 @@ public static int findLengthOfLCIS(int[] nums) { } ``` -Python: +### Python: DP ```python @@ -261,7 +260,8 @@ class Solution: return result ``` -Go: +### Go: + > 动态规划: ```go func findLengthOfLCIS(nums []int) int { @@ -302,7 +302,8 @@ func findLengthOfLCIS(nums []int) int { } ``` -Rust: +### Rust: + ```rust pub fn find_length_of_lcis(nums: Vec) -> i32 { if nums.is_empty() { @@ -320,7 +321,7 @@ pub fn find_length_of_lcis(nums: Vec) -> i32 { } ``` -Javascript: +### Javascript: > 动态规划: ```javascript @@ -363,7 +364,7 @@ const findLengthOfLCIS = (nums) => { }; ``` -TypeScript: +### TypeScript: > 动态规划: @@ -409,3 +410,4 @@ function findLengthOfLCIS(nums: number[]): number { + From 9b0c0f20dcc1fd75af00188a04886dee7adc8c60 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 16:07:52 +0800 Subject: [PATCH 12/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200392.=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E5=AD=90=E5=BA=8F=E5=88=97=200718.=E6=9C=80=E9=95=BF?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=AD=90=E6=95=B0=E7=BB=84=201035.=E4=B8=8D?= =?UTF-8?q?=E7=9B=B8=E4=BA=A4=E7=9A=84=E7=BA=BF=201143.=E6=9C=80=E9=95=BF?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E5=AD=90=E5=BA=8F=E5=88=97=20=E6=8E=92?= =?UTF-8?q?=E7=89=88=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...55\345\255\220\345\272\217\345\210\227.md" | 16 +++++++++------- ...15\345\255\220\346\225\260\347\273\204.md" | 18 +++++++++--------- ...70\344\272\244\347\232\204\347\272\277.md" | 17 +++++++++-------- ...61\345\255\220\345\272\217\345\210\227.md" | 19 ++++++++++++------- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git "a/problems/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.md" "b/problems/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.md" index c10114c05a..6342a41f00 100644 --- "a/problems/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.md" +++ "b/problems/0392.\345\210\244\346\226\255\345\255\220\345\272\217\345\210\227.md" @@ -28,9 +28,9 @@ 两个字符串都只由小写字符组成。 -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划,用相似思路解决复杂问题 | LeetCode:392.判断子序列](https://www.bilibili.com/video/BV1tv4y1B7ym/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划,用相似思路解决复杂问题 | LeetCode:392.判断子序列](https://www.bilibili.com/video/BV1tv4y1B7ym/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -149,8 +149,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java class Solution { public boolean isSubsequence(String s, String t) { @@ -174,7 +174,8 @@ class Solution { } ``` -Python: +### Python: + ```python class Solution: def isSubsequence(self, s: str, t: str) -> bool: @@ -190,7 +191,7 @@ class Solution: return False ``` -JavaScript: +### JavaScript: ```javascript const isSubsequence = (s, t) => { @@ -213,7 +214,7 @@ const isSubsequence = (s, t) => { }; ``` -TypeScript: +### TypeScript: ```typescript function isSubsequence(s: string, t: string): boolean { @@ -237,7 +238,7 @@ function isSubsequence(s: string, t: string): boolean { }; ``` -Go: +### Go: ```go func isSubsequence(s string, t string) bool { @@ -266,3 +267,4 @@ func isSubsequence(s string, t string) bool { + diff --git "a/problems/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.md" "b/problems/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.md" index 82bf4f59e2..18cc02407f 100644 --- "a/problems/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.md" +++ "b/problems/0718.\346\234\200\351\225\277\351\207\215\345\244\215\345\255\220\346\225\260\347\273\204.md" @@ -25,9 +25,7 @@ ## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划之子序列问题,想清楚DP数组的定义 | LeetCode:718.最长重复子数组](https://www.bilibili.com/video/BV178411H7hV),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 - - +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之子序列问题,想清楚DP数组的定义 | LeetCode:718.最长重复子数组](https://www.bilibili.com/video/BV178411H7hV),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -126,7 +124,7 @@ public: * 时间复杂度:O(n × m),n 为A长度,m为B长度 * 空间复杂度:O(n × m) -## 滚动数组 +### 滚动数组 在如下图中: @@ -257,8 +255,8 @@ class Solution { ## 其他语言版本 +### Java: -Java: ```java // 版本一 class Solution { @@ -300,7 +298,7 @@ class Solution { } ``` -Python: +### Python: 2维DP ```python @@ -395,7 +393,8 @@ class Solution: ``` -Go: +### Go: + ```Go func findLength(A []int, B []int) int { m, n := len(A), len(B) @@ -442,7 +441,7 @@ func max(a, b int) int { } ``` -JavaScript: +### JavaScript: > 动态规划 @@ -489,7 +488,7 @@ const findLength = (nums1, nums2) => { } ``` -TypeScript: +### TypeScript: > 动态规划: @@ -544,3 +543,4 @@ function findLength(nums1: number[], nums2: number[]): number { + diff --git "a/problems/1035.\344\270\215\347\233\270\344\272\244\347\232\204\347\272\277.md" "b/problems/1035.\344\270\215\347\233\270\344\272\244\347\232\204\347\272\277.md" index 7142d75c09..74e94c842f 100644 --- "a/problems/1035.\344\270\215\347\233\270\344\272\244\347\232\204\347\272\277.md" +++ "b/problems/1035.\344\270\215\347\233\270\344\272\244\347\232\204\347\272\277.md" @@ -19,7 +19,7 @@ ## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划之子序列问题,换汤不换药 | LeetCode:1035.不相交的线](https://www.bilibili.com/video/BV1h84y1x7MP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划之子序列问题,换汤不换药 | LeetCode:1035.不相交的线](https://www.bilibili.com/video/BV1h84y1x7MP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -82,8 +82,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java class Solution { public int maxUncrossedLines(int[] nums1, int[] nums2) { @@ -106,7 +106,8 @@ Java: } ``` -Python: +### Python: + ```python class Solution: def maxUncrossedLines(self, A: List[int], B: List[int]) -> int: @@ -120,8 +121,7 @@ class Solution: return dp[-1][-1] ``` - -Golang: +### Go: ```go func maxUncrossedLines(A []int, B []int) int { @@ -152,7 +152,7 @@ func max(a, b int) int { } ``` -Rust: +### Rust: ```rust pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 { @@ -173,7 +173,7 @@ pub fn max_uncrossed_lines(nums1: Vec, nums2: Vec) -> i32 { } ``` -JavaScript: +### JavaScript: ```javascript const maxUncrossedLines = (nums1, nums2) => { @@ -196,7 +196,7 @@ const maxUncrossedLines = (nums1, nums2) => { }; ``` -TypeScript: +### TypeScript: ```typescript function maxUncrossedLines(nums1: number[], nums2: number[]): number { @@ -224,3 +224,4 @@ function maxUncrossedLines(nums1: number[], nums2: number[]): number { + diff --git "a/problems/1143.\346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227.md" "b/problems/1143.\346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227.md" index 68269b87c5..260b085e14 100644 --- "a/problems/1143.\346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227.md" +++ "b/problems/1143.\346\234\200\351\225\277\345\205\254\345\205\261\345\255\220\345\272\217\345\210\227.md" @@ -39,7 +39,7 @@ ## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划子序列问题经典题目 | LeetCode:1143.最长公共子序列](https://www.bilibili.com/video/BV1ye4y1L7CQ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划子序列问题经典题目 | LeetCode:1143.最长公共子序列](https://www.bilibili.com/video/BV1ye4y1L7CQ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -136,7 +136,7 @@ public: ## 其他语言版本 -Java: +### Java: ```java /* @@ -207,8 +207,9 @@ class Solution { } ``` -Python: +### Python: 2维DP + ```python class Solution: def longestCommonSubsequence(self, text1: str, text2: str) -> int: @@ -252,7 +253,8 @@ class Solution: ``` -Go: +### Go: + ```Go func longestCommonSubsequence(text1 string, text2 string) int { t1 := len(text1) @@ -283,7 +285,8 @@ func max(a,b int)int { ``` -Javascript: +### JavaScript: + ```javascript const longestCommonSubsequence = (text1, text2) => { let dp = Array.from(Array(text1.length+1), () => Array(text2.length+1).fill(0)); @@ -302,7 +305,7 @@ const longestCommonSubsequence = (text1, text2) => { }; ``` -TypeScript: +### TypeScript: ```typescript function longestCommonSubsequence(text1: string, text2: string): number { @@ -326,7 +329,8 @@ function longestCommonSubsequence(text1: string, text2: string): number { }; ``` -Rust: +### Rust: + ```rust pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { let (n, m) = (text1.len(), text2.len()); @@ -353,3 +357,4 @@ pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { + From a0edc60d1fd08db91138daf430a97894a354bd98 Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 16:21:21 +0800 Subject: [PATCH 13/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E7=B3=BB=E5=88=97=20=E6=8E=92=E7=89=88?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...26\350\276\221\350\267\235\347\246\273.md" | 19 +++++++++++-------- ...04\345\255\220\345\272\217\345\210\227.md" | 18 ++++++++++-------- ...40\351\231\244\346\223\215\344\275\234.md" | 16 +++++++++------- ...11\346\255\245\351\223\272\345\236\253.md" | 8 ++------ 4 files changed, 32 insertions(+), 29 deletions(-) diff --git "a/problems/0072.\347\274\226\350\276\221\350\267\235\347\246\273.md" "b/problems/0072.\347\274\226\350\276\221\350\267\235\347\246\273.md" index 703e891311..1ed9a86083 100644 --- "a/problems/0072.\347\274\226\350\276\221\350\267\235\347\246\273.md" +++ "b/problems/0072.\347\274\226\350\276\221\350\267\235\347\246\273.md" @@ -40,8 +40,8 @@ exection -> execution (插入 'u') * 0 <= word1.length, word2.length <= 500 * word1 和 word2 由小写英文字母组成 -# 算法公开课 -**《代码随想录》算法视频公开课:[动态规划终极绝杀! LeetCode:72.编辑距离](https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +## 算法公开课 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[动态规划终极绝杀! LeetCode:72.编辑距离](https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -227,8 +227,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java public int minDistance(String word1, String word2) { int m = word1.length(); @@ -256,7 +256,8 @@ public int minDistance(String word1, String word2) { } ``` -Python: +### Python: + ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: @@ -274,7 +275,8 @@ class Solution: return dp[-1][-1] ``` -Go: +### Go: + ```Go func minDistance(word1 string, word2 string) int { m, n := len(word1), len(word2) @@ -310,8 +312,8 @@ func Min(args ...int) int { } ``` +### Javascript: -Javascript: ```javascript const minDistance = (word1, word2) => { let dp = Array.from(Array(word1.length + 1), () => Array(word2.length+1).fill(0)); @@ -338,7 +340,7 @@ const minDistance = (word1, word2) => { }; ``` -TypeScript: +### TypeScript: ```typescript function minDistance(word1: string, word2: string): number { @@ -373,7 +375,7 @@ function minDistance(word1: string, word2: string): number { }; ``` -C: +### C: ```c @@ -405,3 +407,4 @@ int minDistance(char * word1, char * word2){ + diff --git "a/problems/0115.\344\270\215\345\220\214\347\232\204\345\255\220\345\272\217\345\210\227.md" "b/problems/0115.\344\270\215\345\220\214\347\232\204\345\255\220\345\272\217\345\210\227.md" index 8c82880d58..d925c5dede 100644 --- "a/problems/0115.\344\270\215\345\220\214\347\232\204\345\255\220\345\272\217\345\210\227.md" +++ "b/problems/0115.\344\270\215\345\220\214\347\232\204\345\255\220\345\272\217\345\210\227.md" @@ -157,8 +157,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java class Solution { public int numDistinct(String s, String t) { @@ -182,7 +182,8 @@ class Solution { } ``` -Python: +### Python: + ```python class Solution: def numDistinct(self, s: str, t: str) -> int: @@ -200,7 +201,8 @@ class Solution: return dp[-1][-1] ``` -Python3: +### Python3: + ```python class SolutionDP2: """ @@ -234,7 +236,8 @@ class SolutionDP2: return dp[-1] ``` -Go: +### Go: + ```go func numDistinct(s string, t string) int { dp:= make([][]int,len(s)+1) @@ -259,8 +262,8 @@ func numDistinct(s string, t string) int { } ``` +### Javascript: -Javascript: ```javascript const numDistinct = (s, t) => { let dp = Array.from(Array(s.length + 1), () => Array(t.length +1).fill(0)); @@ -283,7 +286,7 @@ const numDistinct = (s, t) => { }; ``` -TypeScript: +### TypeScript: ```typescript function numDistinct(s: string, t: string): number { @@ -312,9 +315,8 @@ function numDistinct(s: string, t: string): number { ``` - -

+ diff --git "a/problems/0583.\344\270\244\344\270\252\345\255\227\347\254\246\344\270\262\347\232\204\345\210\240\351\231\244\346\223\215\344\275\234.md" "b/problems/0583.\344\270\244\344\270\252\345\255\227\347\254\246\344\270\262\347\232\204\345\210\240\351\231\244\346\223\215\344\275\234.md" index 48d15b0ba9..505a4e33ee 100644 --- "a/problems/0583.\344\270\244\344\270\252\345\255\227\347\254\246\344\270\262\347\232\204\345\210\240\351\231\244\346\223\215\344\275\234.md" +++ "b/problems/0583.\344\270\244\344\270\252\345\255\227\347\254\246\344\270\262\347\232\204\345\210\240\351\231\244\346\223\215\344\275\234.md" @@ -17,9 +17,9 @@ * 解释: 第一步将"sea"变为"ea",第二步将"eat"变为"ea" -# 算法公开课 +## 算法公开课 -**《代码随想录》算法视频公开课:[动态规划之子序列,还是为了编辑距离做铺垫 | LeetCode:583.两个字符串的删除操(https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 +**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[LeetCode:583.两个字符串的删除操](https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 ## 思路 @@ -143,8 +143,8 @@ public: ## 其他语言版本 +### Java: -Java: ```java // dp数组中存储word1和word2最长相同子序列的长度 class Solution { @@ -215,8 +215,8 @@ class Solution { } ``` +### Python: -Python: ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: @@ -234,7 +234,8 @@ class Solution: return dp[-1][-1] ``` -Go: +### Go: + ```go func minDistance(word1 string, word2 string) int { dp := make([][]int, len(word1)+1) @@ -267,7 +268,8 @@ func min(a, b int) int { return b } ``` -Javascript: +### Javascript: + ```javascript // 方法一 var minDistance = (word1, word2) => { @@ -309,7 +311,7 @@ var minDistance = function (word1, word2) { }; ``` -TypeScript: +### TypeScript: > dp版本一: diff --git "a/problems/\344\270\272\344\272\206\347\273\235\346\235\200\347\274\226\350\276\221\350\267\235\347\246\273\357\274\214\345\215\241\345\260\224\345\201\232\344\272\206\344\270\211\346\255\245\351\223\272\345\236\253.md" "b/problems/\344\270\272\344\272\206\347\273\235\346\235\200\347\274\226\350\276\221\350\267\235\347\246\273\357\274\214\345\215\241\345\260\224\345\201\232\344\272\206\344\270\211\346\255\245\351\223\272\345\236\253.md" index b8adffc775..50287ce20b 100644 --- "a/problems/\344\270\272\344\272\206\347\273\235\346\235\200\347\274\226\350\276\221\350\267\235\347\246\273\357\274\214\345\215\241\345\260\224\345\201\232\344\272\206\344\270\211\346\255\245\351\223\272\345\236\253.md" +++ "b/problems/\344\270\272\344\272\206\347\273\235\346\235\200\347\274\226\350\276\221\350\267\235\347\246\273\357\274\214\345\215\241\345\260\224\345\201\232\344\272\206\344\270\211\346\255\245\351\223\272\345\236\253.md" @@ -163,8 +163,8 @@ else { ## 其他语言版本 +### Java: -Java: ```java class Solution { public int minDistance(String word1, String word2) { @@ -193,11 +193,6 @@ class Solution { } ``` -Python: - - -Go: - @@ -205,3 +200,4 @@ Go: + From 4760924db0d9d5f53719ed36fe0b3d201cfb3c6f Mon Sep 17 00:00:00 2001 From: jinbudaily <18336218010@163.com> Date: Wed, 26 Jul 2023 16:25:35 +0800 Subject: [PATCH 14/14] =?UTF-8?q?=E6=9B=B4=E6=96=B0=200516.=E6=9C=80?= =?UTF-8?q?=E9=95=BF=E5=9B=9E=E6=96=87=E5=AD=90=E5=BA=8F=E5=88=97=200647.?= =?UTF-8?q?=E5=9B=9E=E6=96=87=E5=AD=90=E4=B8=B2=20=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E8=A7=84=E5=88=92=E6=80=BB=E7=BB=93=20=E6=8E=92=E7=89=88?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...07\345\255\220\345\272\217\345\210\227.md" | 13 ++++++------ ...36\346\226\207\345\255\220\344\270\262.md" | 21 ++++++++++++------- ...22\346\200\273\347\273\223\347\257\207.md" | 1 + 3 files changed, 20 insertions(+), 15 deletions(-) diff --git "a/problems/0516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.md" "b/problems/0516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.md" index fcdd57b0f4..8092758389 100644 --- "a/problems/0516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.md" +++ "b/problems/0516.\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.md" @@ -152,8 +152,7 @@ public: ## 其他语言版本 - -Java: +### Java: ```java public class Solution { @@ -175,8 +174,7 @@ public class Solution { } ``` - -Python: +### Python: ```python class Solution: @@ -193,7 +191,7 @@ class Solution: return dp[0][-1] ``` -Go: +### Go: ```Go func longestPalindromeSubseq(s string) int { @@ -222,7 +220,7 @@ func longestPalindromeSubseq(s string) int { } ``` -Javascript: +### Javascript: ```javascript const longestPalindromeSubseq = (s) => { @@ -247,7 +245,7 @@ const longestPalindromeSubseq = (s) => { }; ``` -TypeScript: +### TypeScript: ```typescript function longestPalindromeSubseq(s: string): number { @@ -281,3 +279,4 @@ function longestPalindromeSubseq(s: string): number { + diff --git "a/problems/0647.\345\233\236\346\226\207\345\255\220\344\270\262.md" "b/problems/0647.\345\233\236\346\226\207\345\255\220\344\270\262.md" index 084b9f74e6..fdf83736a0 100644 --- "a/problems/0647.\345\233\236\346\226\207\345\255\220\344\270\262.md" +++ "b/problems/0647.\345\233\236\346\226\207\345\255\220\344\270\262.md" @@ -26,11 +26,13 @@ 提示:输入的字符串长度不会超过 1000 。 -## 暴力解法 +## 思路 + +### 暴力解法 两层for循环,遍历区间起始位置和终止位置,然后还需要一层遍历判断这个区间是不是回文。所以时间复杂度:O(n^3) -## 动态规划 +### 动态规划 动规五部曲: @@ -187,7 +189,7 @@ public: * 时间复杂度:O(n^2) * 空间复杂度:O(n^2) -## 双指针法 +### 双指针法 动态规划的空间复杂度是偏高的,我们再看一下双指针法。 @@ -231,7 +233,7 @@ public: ## 其他语言版本 -Java: +### Java: 动态规划: @@ -337,7 +339,7 @@ class Solution { } ``` -Python: +### Python: > 动态规划: ```python @@ -390,7 +392,8 @@ class Solution: return res ``` -Go: +### Go: + ```Go func countSubstrings(s string) int { res:=0 @@ -416,7 +419,8 @@ func countSubstrings(s string) int { } ``` -Javascript +### Javascript: + > 动态规划 ```javascript const countSubstrings = (s) => { @@ -462,7 +466,7 @@ const countSubstrings = (s) => { } ``` -TypeScript: +### TypeScript: > 动态规划: @@ -524,3 +528,4 @@ function expandRange(s: string, left: number, right: number): number { + diff --git "a/problems/\345\212\250\346\200\201\350\247\204\345\210\222\346\200\273\347\273\223\347\257\207.md" "b/problems/\345\212\250\346\200\201\350\247\204\345\210\222\346\200\273\347\273\223\347\257\207.md" index 8a1531f8be..c86376d349 100644 --- "a/problems/\345\212\250\346\200\201\350\247\204\345\210\222\346\200\273\347\273\223\347\257\207.md" +++ "b/problems/\345\212\250\346\200\201\350\247\204\345\210\222\346\200\273\347\273\223\347\257\207.md" @@ -136,3 +136,4 @@ +