Merge branch 'youngyangyang04:master' into master

This commit is contained in:
niuli
2023-07-27 16:19:40 +08:00
committed by GitHub
53 changed files with 605 additions and 335 deletions

View File

@ -5,11 +5,11 @@
> 1. **介绍** :本项目是一套完整的刷题计划,旨在帮助大家少走弯路,循序渐进学算法,[关注作者](#关于作者) > 1. **介绍** :本项目是一套完整的刷题计划,旨在帮助大家少走弯路,循序渐进学算法,[关注作者](#关于作者)
> 2. **正式出版** [《代码随想录》](https://programmercarl.com/other/publish.html) 。 > 2. **正式出版** [《代码随想录》](https://programmercarl.com/other/publish.html) 。
> 3. **PDF版本** [「代码随想录」算法精讲 PDF 版本](https://programmercarl.com/other/algo_pdf.html) 。 > 3. **PDF版本** [「代码随想录」算法精讲 PDF 版本](https://programmercarl.com/other/algo_pdf.html) 。
> 4. **算法公开课** [《代码随想录》算法视频公开课](https://www.bilibili.com/video/BV1fA4y1o715) 。 > 4. **算法公开课** [《代码随想录》算法视频公开课](https://www.programmercarl.com/other/gongkaike.html) 。
> 5. **最强八股文** [代码随想录知识星球精华PDF](https://www.programmercarl.com/other/kstar_baguwen.html) 。 > 5. **最强八股文** [代码随想录知识星球精华PDF](https://www.programmercarl.com/other/kstar_baguwen.html) 。
> 6. **刷题顺序** README已经将刷题顺序排好了按照顺序一道一道刷就可以。 > 6. **刷题顺序** README已经将刷题顺序排好了按照顺序一道一道刷就可以。
> 7. **学习社区** :一起学习打卡/面试技巧/如何选择offer/大厂内推/职场规则/简历修改/技术分享/程序人生。欢迎加入[「代码随想录」知识星球](https://programmercarl.com/other/kstar.html) 。 > 7. **学习社区** :一起学习打卡/面试技巧/如何选择offer/大厂内推/职场规则/简历修改/技术分享/程序人生。欢迎加入[「代码随想录」知识星球](https://programmercarl.com/other/kstar.html) 。
> 8. **提交代码** 本项目统一使用C++语言进行讲解但已经有Java、Python、Go、JavaScript等等多语言版本感谢[这里的每一位贡献者](https://github.com/youngyangyang04/leetcode-master/graphs/contributors),如果你也想贡献代码点亮你的头像,[点击这里](https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A)了解提交代码的方式。 > 8. **提交代码** 本项目统一使用C++语言进行讲解但已经有Java、Python、Go、JavaScript等等多语言版本感谢[这里的每一位贡献者](https://github.com/youngyangyang04/leetcode-master/graphs/contributors),如果你也想贡献代码点亮你的头像,[点击这里](https://www.programmercarl.com/qita/join.html)了解提交代码的方式。
> 9. **转载须知** :以下所有文章皆为我([程序员Carl](https://github.com/youngyangyang04))的原创。引用本项目文章请注明出处,发现恶意抄袭或搬运,会动用法律武器维护自己的权益。让我们一起维护一个良好的技术创作环境! > 9. **转载须知** :以下所有文章皆为我([程序员Carl](https://github.com/youngyangyang04))的原创。引用本项目文章请注明出处,发现恶意抄袭或搬运,会动用法律武器维护自己的权益。让我们一起维护一个良好的技术创作环境!
@ -51,19 +51,12 @@
## 如何使用该刷题攻略 ## 如何使用该刷题攻略
电脑端还看不到留言,大家可以在公众号[「代码随想录」](https://img-blog.csdnimg.cn/20201124161234338.png),左下角有「刷题攻略」,这是手机版刷题攻略,看完就会发现有很多录友(代码随想录的朋友们)在文章下留言打卡,这份刷题顺序和题解已经陪伴了上万录友了,同时也说明文章的质量是经过上万人的考验! 按照先面的排列顺序,从数组开始刷起就可以了,顺序都安排好了,按顺序刷就好。
欢迎每一位学习算法的小伙伴加入到这个学习阵营来!
**目前已经更新了,数组-> 链表-> 哈希表->字符串->栈与队列->树->回溯->贪心,八个专题了,正在讲解动态规划!**
在刷题攻略中,每个专题开始都有理论基础篇,并不像是教科书般的理论介绍,而是从实战中归纳需要的基础知识。每个专题结束都有总结篇,最这个专题的归纳总结。 在刷题攻略中,每个专题开始都有理论基础篇,并不像是教科书般的理论介绍,而是从实战中归纳需要的基础知识。每个专题结束都有总结篇,最这个专题的归纳总结。
如果你是算法老手,这篇攻略也是复习的最佳资料,如果把每个系列对应的总结篇,快速过一遍,整个算法知识体系以及各种解法就重现脑海了。 如果你是算法老手,这篇攻略也是复习的最佳资料,如果把每个系列对应的总结篇,快速过一遍,整个算法知识体系以及各种解法就重现脑海了。
目前「代码随想录」刷题攻略更新了:**200多篇文章精讲了200道经典算法题目共60w字的详细图解大部分题目都搭配了20分钟左右的视频讲解**,视频质量很好,口碑很好,大家可以去看看,视频列表:[代码随想录视频讲解](https://www.bilibili.com/video/BV1fA4y1o715)。
**这里每一篇题解,都是精品,值得仔细琢磨** **这里每一篇题解,都是精品,值得仔细琢磨**
我在题目讲解中统一使用C++但你会发现下面几乎每篇题解都配有其他语言版本Java、Python、Go、JavaScript等等正是这些[热心小伙们](https://github.com/youngyangyang04/leetcode-master/graphs/contributors)贡献的代码,当然我也会严格把控代码质量。 我在题目讲解中统一使用C++但你会发现下面几乎每篇题解都配有其他语言版本Java、Python、Go、JavaScript等等正是这些[热心小伙们](https://github.com/youngyangyang04/leetcode-master/graphs/contributors)贡献的代码,当然我也会严格把控代码质量。
@ -100,14 +93,11 @@
* [程序员应该用什么用具来写文档?](./problems/前序/程序员写文档工具.md) * [程序员应该用什么用具来写文档?](./problems/前序/程序员写文档工具.md)
* 求职 * 求职
* [ACM模式练习网站卡码网](https://kamacoder.com/)
* [程序员的简历应该这么写!!(附简历模板)](./problems/前序/程序员简历.md) * [程序员的简历应该这么写!!(附简历模板)](./problems/前序/程序员简历.md)
* [【专业技能】应该这样写!](https://programmercarl.com/other/jianlizhuanye.html)
* [【项目经历】应该这样写!](https://programmercarl.com/other/jianlixiangmu.html)
* [BAT级别技术面试流程和注意事项都在这里了](./problems/前序/BAT级别技术面试流程和注意事项都在这里了.md) * [BAT级别技术面试流程和注意事项都在这里了](./problems/前序/BAT级别技术面试流程和注意事项都在这里了.md)
* [北京有这些互联网公司,你都知道么?](./problems/前序/北京互联网公司总结.md)
* [上海有这些互联网公司,你都知道么?](./problems/前序/上海互联网公司总结.md)
* [深圳有这些互联网公司,你都知道么?](./problems/前序/深圳互联网公司总结.md)
* [广州有这些互联网公司,你都知道么?](./problems/前序/广州互联网公司总结.md)
* [成都有这些互联网公司,你都知道么?](./problems/前序/成都互联网公司总结.md)
* [杭州有这些互联网公司,你都知道么?](./problems/前序/杭州互联网公司总结.md)
* 算法性能分析 * 算法性能分析
* [关于时间复杂度,你不知道的都在这里!](./problems/前序/关于时间复杂度,你不知道的都在这里!.md) * [关于时间复杂度,你不知道的都在这里!](./problems/前序/关于时间复杂度,你不知道的都在这里!.md)
@ -506,7 +496,7 @@
# 关于作者 # 关于作者
大家好我是程序员Carl哈工大师兄《代码随想录》作者先后在腾讯和百度从事后端技术研发CSDN博客专家。对算法和C++后端技术有一定的见解利用工作之余重新刷leetcode。 大家好我是程序员Carl哈工大师兄《代码随想录》作者先后在腾讯和百度从事后端技术研发。对算法和C++后端技术有一定的见解利用工作之余重新刷leetcode。
加入「代码随想录」刷题小分队(微信群),可以扫下方二维码,加代码随想录客服微信。 加入「代码随想录」刷题小分队(微信群),可以扫下方二维码,加代码随想录客服微信。
@ -527,4 +517,3 @@
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20211026122841.png" data-img="1" width="650" height="500"></img></div> <div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20211026122841.png" data-img="1" width="650" height="500"></img></div>
<!-- 24. [贪心算法714.买卖股票的最佳时机含手续费](./problems/0714.买卖股票的最佳时机含手续费.md) -->

View File

@ -29,9 +29,9 @@
* 1 阶 + 2 阶 * 1 阶 + 2 阶
* 2 阶 + 1 阶 * 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 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -127,8 +127,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java:
Java
```java ```java
class Solution { class Solution {
public int climbStairs(int n) { public int climbStairs(int n) {
@ -148,7 +148,7 @@ class Solution {
} }
``` ```
Python3 ### Python3
```python ```python
@ -166,8 +166,8 @@ class Solution:
return dp[n] return dp[n]
``` ```
### Go
Go
```go ```go
func climbStairs(n int) int { func climbStairs(n int) int {
//定义 //定义
@ -189,7 +189,8 @@ func climbStairs(n int) int {
} }
``` ```
JavaScript: ### JavaScript:
```javascript ```javascript
var climbStairs = function(n) { var climbStairs = function(n) {
const dp = new Array(n + 1).fill(0); const dp = new Array(n + 1).fill(0);
@ -206,7 +207,7 @@ var climbStairs = function(n) {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function climbStairs(n: number): number { function climbStairs(n: number): number {
@ -226,7 +227,7 @@ function climbStairs(n: number): number {
}; };
``` ```
Rust: ### Rust:
```rust ```rust
impl Solution { impl Solution {
@ -250,4 +251,3 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -40,8 +40,8 @@ exection -> execution (插入 'u')
* 0 <= word1.length, word2.length <= 500 * 0 <= word1.length, word2.length <= 500
* word1 和 word2 由小写英文字母组成 * word1 和 word2 由小写英文字母组成
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划终极绝杀! LeetCode72.编辑距离](https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划终极绝杀! LeetCode72.编辑距离](https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -227,8 +227,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
public int minDistance(String word1, String word2) { public int minDistance(String word1, String word2) {
int m = word1.length(); int m = word1.length();
@ -256,7 +256,8 @@ public int minDistance(String word1, String word2) {
} }
``` ```
Python ### Python
```python ```python
class Solution: class Solution:
def minDistance(self, word1: str, word2: str) -> int: def minDistance(self, word1: str, word2: str) -> int:
@ -274,7 +275,8 @@ class Solution:
return dp[-1][-1] return dp[-1][-1]
``` ```
Go ### Go
```Go ```Go
func minDistance(word1 string, word2 string) int { func minDistance(word1 string, word2 string) int {
m, n := len(word1), len(word2) m, n := len(word1), len(word2)
@ -310,8 +312,8 @@ func Min(args ...int) int {
} }
``` ```
### Javascript
Javascript
```javascript ```javascript
const minDistance = (word1, word2) => { const minDistance = (word1, word2) => {
let dp = Array.from(Array(word1.length + 1), () => Array(word2.length+1).fill(0)); 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 ```typescript
function minDistance(word1: string, word2: string): number { function minDistance(word1: string, word2: string): number {
@ -373,7 +375,7 @@ function minDistance(word1: string, word2: string): number {
}; };
``` ```
C ### C
```c ```c
@ -405,3 +407,4 @@ int minDistance(char * word1, char * word2){
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -157,8 +157,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
class Solution { class Solution {
public int numDistinct(String s, String t) { public int numDistinct(String s, String t) {
@ -182,7 +182,8 @@ class Solution {
} }
``` ```
Python ### Python
```python ```python
class Solution: class Solution:
def numDistinct(self, s: str, t: str) -> int: def numDistinct(self, s: str, t: str) -> int:
@ -200,7 +201,8 @@ class Solution:
return dp[-1][-1] return dp[-1][-1]
``` ```
Python3: ### Python3:
```python ```python
class SolutionDP2: class SolutionDP2:
""" """
@ -234,7 +236,8 @@ class SolutionDP2:
return dp[-1] return dp[-1]
``` ```
Go ### Go
```go ```go
func numDistinct(s string, t string) int { func numDistinct(s string, t string) int {
dp:= make([][]int,len(s)+1) dp:= make([][]int,len(s)+1)
@ -259,8 +262,8 @@ func numDistinct(s string, t string) int {
} }
``` ```
### Javascript:
Javascript:
```javascript ```javascript
const numDistinct = (s, t) => { const numDistinct = (s, t) => {
let dp = Array.from(Array(s.length + 1), () => Array(t.length +1).fill(0)); 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 ```typescript
function numDistinct(s: string, t: string): number { function numDistinct(s: string, t: string): number {
@ -312,9 +315,8 @@ function numDistinct(s: string, t: string): number {
``` ```
<p align="center"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -24,11 +24,9 @@
* 输出0 * 输出0
解释:在这种情况下, 没有交易完成, 所以最大利润为 0。 解释:在这种情况下, 没有交易完成, 所以最大利润为 0。
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划之 LeetCode121.买卖股票的最佳时机1](https://www.bilibili.com/video/BV1Xe4y1u77q),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之 LeetCode121.买卖股票的最佳时机1](https://www.bilibili.com/video/BV1Xe4y1u77q),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -202,7 +200,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java: ### Java:
> 贪心法: > 贪心法:
@ -294,8 +292,7 @@ class Solution {
``` ```
### Python:
Python:
> 贪心法: > 贪心法:
```python ```python
@ -351,7 +348,8 @@ class Solution:
return dp1 return dp1
``` ```
Go: ### Go:
> 贪心法: > 贪心法:
```Go ```Go
func maxProfit(prices []int) int { 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:
> 贪心 > 贪心

View File

@ -34,9 +34,9 @@
* 1 <= prices.length <= 3 * 10 ^ 4 * 1 <= prices.length <= 3 * 10 ^ 4
* 0 <= prices[i] <= 10 ^ 4 * 0 <= prices[i] <= 10 ^ 4
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,股票问题第二弹 | LeetCode122.买卖股票的最佳时机II](https://www.bilibili.com/video/BV1D24y1Q7Ls),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,股票问题第二弹 | LeetCode122.买卖股票的最佳时机II](https://www.bilibili.com/video/BV1D24y1Q7Ls),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -133,8 +133,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
// 动态规划 // 动态规划
class Solution class Solution
@ -191,7 +191,7 @@ class Solution {
} }
``` ```
Python ### Python
> 版本一: > 版本一:
```python ```python
@ -221,7 +221,8 @@ class Solution:
return dp[(length-1) % 2][1] return dp[(length-1) % 2][1]
``` ```
Go ### Go
```go ```go
// 买卖股票的最佳时机Ⅱ 动态规划 // 买卖股票的最佳时机Ⅱ 动态规划
// 时间复杂度O(n) 空间复杂度O(n) // 时间复杂度O(n) 空间复杂度O(n)
@ -250,7 +251,8 @@ func max(a, b int) int {
} }
``` ```
Javascript ### JavaScript
```javascript ```javascript
// 方法一动态规划dp 数组) // 方法一动态规划dp 数组)
const maxProfit = (prices) => { 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 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -39,9 +39,9 @@
* 1 <= prices.length <= 10^5 * 1 <= prices.length <= 10^5
* 0 <= prices[i] <= 10^5 * 0 <= prices[i] <= 10^5
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,股票至多买卖两次,怎么求? | LeetCode123.买卖股票最佳时机III](https://www.bilibili.com/video/BV1WG411K7AR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,股票至多买卖两次,怎么求? | LeetCode123.买卖股票最佳时机III](https://www.bilibili.com/video/BV1WG411K7AR),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -221,7 +221,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java: ### Java:
```java ```java
// 版本一 // 版本一
@ -277,7 +277,7 @@ class Solution {
} }
``` ```
Python: ### Python:
> 版本一: > 版本一:
```python ```python
@ -314,7 +314,7 @@ class Solution:
return dp[4] return dp[4]
``` ```
Go: ### Go:
```go ```go
func maxProfit(prices []int) int { 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 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -33,9 +33,9 @@
* 输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] * 输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
* 输出: false * 输出: false
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[你的背包如何装满?| LeetCode139.单词拆分](https://www.bilibili.com/video/BV1pd4y147Rh/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[你的背包如何装满?| LeetCode139.单词拆分](https://www.bilibili.com/video/BV1pd4y147Rh/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -123,7 +123,7 @@ public:
**这个代码就可以AC了当然回溯算法不是本题的主菜背包才是** **这个代码就可以AC了当然回溯算法不是本题的主菜背包才是**
## 背包问题 ### 背包问题
单词就是物品字符串s就是背包单词能否组成字符串s就是问物品能不能把背包装满。 单词就是物品字符串s就是背包单词能否组成字符串s就是问物品能不能把背包装满。
@ -259,8 +259,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
class Solution { class Solution {
public boolean wordBreak(String s, List<String> wordDict) { public boolean wordBreak(String s, List<String> wordDict) {
@ -335,7 +335,7 @@ class Solution {
} }
``` ```
Python ### Python
回溯 回溯
```python ```python
@ -397,7 +397,8 @@ class Solution:
Go ### Go
```Go ```Go
func wordBreak(s string,wordDict []string) bool { func wordBreak(s string,wordDict []string) bool {
wordDictSet := make(map[string]bool) wordDictSet := make(map[string]bool)
@ -433,7 +434,8 @@ func wordBreak(s string, wordDict []string) bool {
} }
``` ```
Javascript ### JavaScript
```javascript ```javascript
const wordBreak = (s, wordDict) => { 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 ```rust
impl Solution { impl Solution {
@ -519,3 +521,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -31,9 +31,9 @@
* 0 <= prices.length <= 1000 * 0 <= prices.length <= 1000
* 0 <= prices[i] <= 1000 * 0 <= prices[i] <= 1000
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划来决定最佳时机至多可以买卖K次| LeetCode188.买卖股票最佳时机4](https://www.bilibili.com/video/BV16M411U7XJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划来决定最佳时机至多可以买卖K次| LeetCode188.买卖股票最佳时机4](https://www.bilibili.com/video/BV16M411U7XJ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -173,7 +173,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java: ### Java:
```java ```java
// 版本一: 三维 dp数组 // 版本一: 三维 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]) dp[j] = max(dp[j],dp[j-1]+prices[i])
return dp[2*k] return dp[2*k]
``` ```
Go: ### Go:
版本一: 版本一:
@ -404,7 +404,7 @@ func max188(a, b int) int {
} }
``` ```
Javascript: ### JavaScript:
```javascript ```javascript
// 方法一:动态规划 // 方法一:动态规划
@ -454,7 +454,7 @@ var maxProfit = function(k, prices) {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function maxProfit(k: number, prices: number[]): number { function maxProfit(k: number, prices: number[]): number {
@ -474,7 +474,7 @@ function maxProfit(k: number, prices: number[]): number {
}; };
``` ```
Rust ### Rust
```rust ```rust
impl Solution { impl Solution {
@ -529,3 +529,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -31,9 +31,9 @@
* 0 <= nums.length <= 100 * 0 <= nums.length <= 100
* 0 <= nums[i] <= 400 * 0 <= nums[i] <= 400
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,偷不偷这个房间呢?| LeetCode198.打家劫舍](https://www.bilibili.com/video/BV1Te411N7SX),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,偷不偷这个房间呢?| LeetCode198.打家劫舍](https://www.bilibili.com/video/BV1Te411N7SX),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -121,8 +121,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
// 动态规划 // 动态规划
class Solution { class Solution {
@ -194,7 +194,7 @@ class Solution {
} }
``` ```
Python ### Python
1维DP 1维DP
```python ```python
@ -255,7 +255,8 @@ class Solution:
``` ```
Go ### Go
```Go ```Go
func rob(nums []int) int { func rob(nums []int) int {
n := len(nums) n := len(nums)
@ -275,7 +276,7 @@ func max(a, b int) int {
} }
``` ```
JavaScript ### JavaScript
```javascript ```javascript
const rob = nums => { const rob = nums => {
@ -291,7 +292,7 @@ const rob = nums => {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function rob(nums: number[]): number { function rob(nums: number[]): number {
@ -314,7 +315,7 @@ function rob(nums: number[]): number {
}; };
``` ```
Rust: ### Rust:
```rust ```rust
impl Solution { impl Solution {
@ -338,4 +339,3 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -31,9 +31,9 @@
* 1 <= nums.length <= 100 * 1 <= nums.length <= 100
* 0 <= nums[i] <= 1000 * 0 <= nums[i] <= 1000
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,房间连成环了那还偷不偷呢?| LeetCode213.打家劫舍II](https://www.bilibili.com/video/BV1oM411B7xq),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,房间连成环了那还偷不偷呢?| LeetCode213.打家劫舍II](https://www.bilibili.com/video/BV1oM411B7xq),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -104,8 +104,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
class Solution { class Solution {
public int rob(int[] nums) { public int rob(int[] nums) {
@ -129,7 +129,7 @@ class Solution {
} }
``` ```
Python ### Python
```Python ```Python
class Solution: class Solution:
@ -219,7 +219,7 @@ class Solution:
``` ```
Go ### Go
```go ```go
// 打家劫舍Ⅱ 动态规划 // 打家劫舍Ⅱ 动态规划
@ -257,7 +257,8 @@ func max(a, b int) int {
} }
``` ```
javascipt: ### JavaScript:
```javascript ```javascript
var rob = function(nums) { var rob = function(nums) {
const n = nums.length const n = nums.length
@ -279,7 +280,7 @@ const robRange = (nums, start, end) => {
return dp[end] return dp[end]
} }
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function rob(nums: number[]): number { function rob(nums: number[]): number {
@ -301,7 +302,7 @@ function robRange(nums: number[], start: number, end: number): number {
} }
``` ```
Rust: ### Rust:
```rust ```rust
impl Solution { impl Solution {
@ -336,3 +337,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -28,9 +28,9 @@
提示: 提示:
* 1 <= n <= 10^4 * 1 <= n <= 10^4
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[换汤不换药!| LeetCode279.完全平方数](https://www.bilibili.com/video/BV12P411T7Br/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[换汤不换药!| LeetCode279.完全平方数](https://www.bilibili.com/video/BV12P411T7Br/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -106,8 +106,6 @@ dp[5] = min(dp[4] + 1, dp[1] + 1) = 2
最后的dp[n]为最终结果。 最后的dp[n]为最终结果。
## C++代码
以上动规五部曲分析完毕C++代码如下: 以上动规五部曲分析完毕C++代码如下:
```CPP ```CPP
@ -165,8 +163,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
class Solution { class Solution {
// 版本一,先遍历物品, 再遍历背包 // 版本一,先遍历物品, 再遍历背包
@ -219,7 +217,7 @@ class Solution {
} }
``` ```
Python ### Python
先遍历物品, 再遍历背包 先遍历物品, 再遍历背包
```python ```python
@ -276,7 +274,8 @@ class Solution:
``` ```
Go ### Go
```go ```go
// 版本一,先遍历物品, 再遍历背包 // 版本一,先遍历物品, 再遍历背包
func numSquares1(n int) int { func numSquares1(n int) int {
@ -327,7 +326,8 @@ func min(a, b int) int {
} }
``` ```
Javascript: ### Javascript:
```Javascript ```Javascript
// 先遍历物品,再遍历背包 // 先遍历物品,再遍历背包
var numSquares1 = function(n) { var numSquares1 = function(n) {
@ -357,7 +357,7 @@ var numSquares2 = function(n) {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
// 先遍历物品 // 先遍历物品
@ -389,7 +389,7 @@ function numSquares(n: number): number {
}; };
``` ```
Rust: ### Rust:
```rust ```rust
// 先遍历背包 // 先遍历背包
@ -439,3 +439,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -33,7 +33,7 @@
## 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划之子序列问题,元素不连续!| LeetCode300.最长递增子序列](https://www.bilibili.com/video/BV1ng411J7xP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之子序列问题,元素不连续!| LeetCode300.最长递增子序列](https://www.bilibili.com/video/BV1ng411J7xP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -124,8 +124,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
class Solution { class Solution {
public int lengthOfLIS(int[] nums) { public int lengthOfLIS(int[] nums) {
@ -147,7 +147,7 @@ class Solution {
} }
``` ```
Python ### Python
DP DP
```python ```python
@ -189,7 +189,8 @@ class Solution:
return len(tails) # 返回递增子序列的长度 return len(tails) # 返回递增子序列的长度
``` ```
Go ### Go
```go ```go
// 动态规划求解 // 动态规划求解
func lengthOfLIS(nums []int) int { func lengthOfLIS(nums []int) int {
@ -248,7 +249,8 @@ func lengthOfLIS(nums []int ) int {
} }
``` ```
Javascript ### Javascript:
```javascript ```javascript
const lengthOfLIS = (nums) => { const lengthOfLIS = (nums) => {
let dp = Array(nums.length).fill(1); let dp = Array(nums.length).fill(1);
@ -267,7 +269,7 @@ const lengthOfLIS = (nums) => {
}; };
``` ```
TypeScript ### TypeScript:
```typescript ```typescript
function lengthOfLIS(nums: number[]): number { function lengthOfLIS(nums: number[]): number {
@ -288,7 +290,8 @@ function lengthOfLIS(nums: number[]): number {
}; };
``` ```
Rust: ### Rust:
```rust ```rust
pub fn length_of_lis(nums: Vec<i32>) -> i32 { pub fn length_of_lis(nums: Vec<i32>) -> i32 {
let mut dp = vec![1; nums.len() + 1]; let mut dp = vec![1; nums.len() + 1];
@ -307,13 +310,8 @@ pub fn length_of_lis(nums: Vec<i32>) -> i32 {
<p align="center"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -20,9 +20,9 @@
* 输出: 3 * 输出: 3
* 解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出] * 解释: 对应的交易状态为: [买入, 卖出, 冷冻期, 买入, 卖出]
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划来决定最佳时机,这次有冷冻期!| LeetCode309.买卖股票的最佳时机含冷冻期](https://www.bilibili.com/video/BV1rP4y1D7ku),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划来决定最佳时机,这次有冷冻期!| LeetCode309.买卖股票的最佳时机含冷冻期](https://www.bilibili.com/video/BV1rP4y1D7ku),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -174,7 +174,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java ### Java
```java ```java
class Solution { class Solution {
@ -273,8 +273,9 @@ class Solution {
} }
``` ```
Python ### Python
版本一 版本一
```python ```python
from typing import List from typing import List
@ -319,7 +320,8 @@ class Solution:
return max(dp[-1][1], dp[-1][2]) return max(dp[-1][1], dp[-1][2])
``` ```
Go ### Go
```go ```go
// 最佳买卖股票时机含冷冻期 动态规划 // 最佳买卖股票时机含冷冻期 动态规划
// 时间复杂度O(n) 空间复杂度O(n) // 时间复杂度O(n) 空间复杂度O(n)
@ -355,7 +357,7 @@ func max(a, b int) int {
} }
``` ```
Javascript: ### Javascript:
```javascript ```javascript
const maxProfit = (prices) => { const maxProfit = (prices) => {
@ -397,7 +399,7 @@ const maxProfit = (prices) => {
}; };
``` ```
TypeScript ### TypeScript
> 版本一,与本文思路一致 > 版本一,与本文思路一致
@ -455,7 +457,7 @@ function maxProfit(prices: number[]): number {
}; };
``` ```
Rust ### Rust
```rust ```rust
impl Solution { impl Solution {
@ -484,3 +486,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -39,9 +39,9 @@
* 1 <= coins[i] <= 2^31 - 1 * 1 <= coins[i] <= 2^31 - 1
* 0 <= amount <= 10^4 * 0 <= amount <= 10^4
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[装满背包最少的物品件数是多少?| LeetCode322.零钱兑换](https://www.bilibili.com/video/BV14K411R7yv/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满背包最少的物品件数是多少?| LeetCode322.零钱兑换](https://www.bilibili.com/video/BV14K411R7yv/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
@ -110,7 +110,6 @@ dp[0] = 0;
dp[amount]为最终结果。 dp[amount]为最终结果。
## C++代码
以上分析完毕C++ 代码如下: 以上分析完毕C++ 代码如下:
```CPP ```CPP
@ -187,8 +186,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
class Solution { class Solution {
public int coinChange(int[] coins, int amount) { public int coinChange(int[] coins, int amount) {
@ -215,7 +214,7 @@ class Solution {
} }
``` ```
Python ### Python
先遍历物品 后遍历背包 先遍历物品 后遍历背包
@ -288,7 +287,8 @@ class Solution:
``` ```
Go ### Go
```go ```go
// 版本一, 先遍历物品,再遍历背包 // 版本一, 先遍历物品,再遍历背包
func coinChange1(coins []int, amount int) int { func coinChange1(coins []int, amount int) int {
@ -352,7 +352,7 @@ func min(a, b int) int {
``` ```
Rust: ### Rust:
```rust ```rust
// 遍历物品 // 遍历物品
@ -398,7 +398,8 @@ impl Solution {
} }
``` ```
Javascript ### Javascript
```javascript ```javascript
// 遍历物品 // 遍历物品
const coinChange = (coins, amount) => { const coinChange = (coins, amount) => {
@ -435,7 +436,7 @@ var coinChange = function(coins, amount) {
} }
``` ```
TypeScript ### TypeScript
```typescript ```typescript
// 遍历物品 // 遍历物品
@ -473,3 +474,4 @@ function coinChange(coins: number[], amount: number): number {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -16,9 +16,9 @@
![337.打家劫舍III](https://code-thinking-1253855093.file.myqcloud.com/pics/20210223173849619.png) ![337.打家劫舍III](https://code-thinking-1253855093.file.myqcloud.com/pics/20210223173849619.png)
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,房间连成树了,偷不偷呢?| LeetCode337.打家劫舍3](https://www.bilibili.com/video/BV1H24y1Q7sY),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,房间连成树了,偷不偷呢?| LeetCode337.打家劫舍3](https://www.bilibili.com/video/BV1H24y1Q7sY),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -523,3 +523,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -31,9 +31,9 @@
因此输出为 7。 因此输出为 7。
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[装满背包有几种方法?求排列数?| LeetCode377.组合总和IV](https://www.bilibili.com/video/BV1V14y1n7B6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满背包有几种方法?求排列数?| LeetCode377.组合总和IV](https://www.bilibili.com/video/BV1V14y1n7B6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -154,8 +154,7 @@ C++测试用例有两个数相加超过int的数据所以需要在if里加上
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
class Solution { class Solution {
@ -174,7 +173,7 @@ class Solution {
} }
``` ```
Python ### Python
卡哥版 卡哥版
@ -207,7 +206,8 @@ class Solution:
``` ```
Go ### Go
```go ```go
func combinationSum4(nums []int, target int) int { func combinationSum4(nums []int, target int) int {
//定义dp数组 //定义dp数组
@ -226,7 +226,8 @@ func combinationSum4(nums []int, target int) int {
} }
``` ```
Javascript ### Javascript
```javascript ```javascript
const combinationSum4 = (nums, target) => { const combinationSum4 = (nums, target) => {
@ -245,7 +246,7 @@ const combinationSum4 = (nums, target) => {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function combinationSum4(nums: number[], target: number): number { function combinationSum4(nums: number[], target: number): number {
@ -264,7 +265,7 @@ function combinationSum4(nums: number[], target: number): number {
}; };
``` ```
Rust ### Rust:
```Rust ```Rust
impl Solution { impl Solution {
@ -289,3 +290,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -28,9 +28,9 @@
两个字符串都只由小写字符组成。 两个字符串都只由小写字符组成。
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,用相似思路解决复杂问题 | LeetCode392.判断子序列](https://www.bilibili.com/video/BV1tv4y1B7ym/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,用相似思路解决复杂问题 | LeetCode392.判断子序列](https://www.bilibili.com/video/BV1tv4y1B7ym/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -149,8 +149,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java:
Java:
```java ```java
class Solution { class Solution {
public boolean isSubsequence(String s, String t) { public boolean isSubsequence(String s, String t) {
@ -174,7 +174,8 @@ class Solution {
} }
``` ```
Python ### Python
```python ```python
class Solution: class Solution:
def isSubsequence(self, s: str, t: str) -> bool: def isSubsequence(self, s: str, t: str) -> bool:
@ -190,7 +191,7 @@ class Solution:
return False return False
``` ```
JavaScript ### JavaScript
```javascript ```javascript
const isSubsequence = (s, t) => { const isSubsequence = (s, t) => {
@ -213,7 +214,7 @@ const isSubsequence = (s, t) => {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function isSubsequence(s: string, t: string): boolean { function isSubsequence(s: string, t: string): boolean {
@ -237,7 +238,7 @@ function isSubsequence(s: string, t: string): boolean {
}; };
``` ```
Go ### Go
```go ```go
func isSubsequence(s string, t string) bool { func isSubsequence(s string, t string) bool {
@ -266,3 +267,4 @@ func isSubsequence(s string, t string) bool {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -30,9 +30,9 @@
* 1 <= nums.length <= 200 * 1 <= nums.length <= 200
* 1 <= nums[i] <= 100 * 1 <= nums[i] <= 100
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划之背包问题,这个包能装满吗?| LeetCode416.分割等和子集](https://www.bilibili.com/video/BV1rt4y1N7jE/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之背包问题,这个包能装满吗?| LeetCode416.分割等和子集](https://www.bilibili.com/video/BV1rt4y1N7jE/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -53,7 +53,7 @@
* [动态规划关于01背包问题你该了解这些](https://programmercarl.com/背包理论基础01背包-1.html) * [动态规划关于01背包问题你该了解这些](https://programmercarl.com/背包理论基础01背包-1.html)
* [动态规划关于01背包问题你该了解这些滚动数组](https://programmercarl.com/背包理论基础01背包-2.html) * [动态规划关于01背包问题你该了解这些滚动数组](https://programmercarl.com/背包理论基础01背包-2.html)
## 01背包问题 ### 01背包问题
背包问题大家都知道有N件物品和一个最多能背重量为W 的背包。第i件物品的重量是weight[i]得到的价值是value[i] 。每件物品只能用一次,求解将哪些物品装入背包里物品价值总和最大。 背包问题大家都知道有N件物品和一个最多能背重量为W 的背包。第i件物品的重量是weight[i]得到的价值是value[i] 。每件物品只能用一次,求解将哪些物品装入背包里物品价值总和最大。
@ -479,7 +479,7 @@ func canPartition(nums []int) bool {
} }
``` ```
### javaScript: ### JavaScript:
```js ```js
var canPartition = function(nums) { var canPartition = function(nums) {
@ -499,7 +499,7 @@ var canPartition = function(nums) {
``` ```
### Rust ### Rust:
```Rust ```Rust
impl Solution { impl Solution {
@ -681,7 +681,7 @@ function canPartition(nums: number[]): boolean {
}; };
``` ```
### Scala ### Scala:
滚动数组: 滚动数组:
```scala ```scala
@ -730,3 +730,4 @@ object Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -34,9 +34,9 @@
* strs[i] 仅由 '0' 和 '1' 组成 * strs[i] 仅由 '0' 和 '1' 组成
* 1 <= m, n <= 100 * 1 <= m, n <= 100
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[装满这个背包最多用多少个物品?| LeetCode474.一和零](https://www.bilibili.com/video/BV1rW4y1x7ZQ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满这个背包最多用多少个物品?| LeetCode474.一和零](https://www.bilibili.com/video/BV1rW4y1x7ZQ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -538,3 +538,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -37,9 +37,9 @@
* 初始的数组的和不会超过 1000 。 * 初始的数组的和不会超过 1000 。
* 保证返回的最终结果能被 32 位整数存下。 * 保证返回的最终结果能被 32 位整数存下。
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[装满背包有多少种方法?| LeetCode494.目标和](https://www.bilibili.com/video/BV1o8411j73x/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满背包有多少种方法?| LeetCode494.目标和](https://www.bilibili.com/video/BV1o8411j73x/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -67,7 +67,7 @@ target是固定的sum是固定的left就可以求出来。
此时问题就是在集合nums中找出和为left的组合。 此时问题就是在集合nums中找出和为left的组合。
## 回溯算法 ### 回溯算法
在回溯算法系列中,一起学过这道题目[回溯算法39. 组合总和](https://programmercarl.com/0039.组合总和.html)的录友应该感觉很熟悉,这不就是组合总和问题么? 在回溯算法系列中,一起学过这道题目[回溯算法39. 组合总和](https://programmercarl.com/0039.组合总和.html)的录友应该感觉很熟悉,这不就是组合总和问题么?
@ -118,7 +118,7 @@ public:
也可以使用记忆化回溯,但这里我就不在回溯上下功夫了,直接看动规吧 也可以使用记忆化回溯,但这里我就不在回溯上下功夫了,直接看动规吧
## 动态规划 ### 动态规划
如何转化为01背包问题呢。 如何转化为01背包问题呢。
@ -519,8 +519,6 @@ const findTargetSumWays = (nums, target) => {
### TypeScript ### TypeScript
TypeScript:
```ts ```ts
function findTargetSumWays(nums: number[], target: number): number { function findTargetSumWays(nums: number[], target: number): number {
// 把数组分成两个组合left, right.left + right = sum, left - right = target. // 把数组分成两个组合left, right.left + right = sum, left - right = target.
@ -590,3 +588,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -32,9 +32,9 @@ F(n) = F(n - 1) + F(n - 2),其中 n > 1
* 0 <= n <= 30 * 0 <= n <= 30
# 视频讲解 ## 算法公开课
**《代码随想录》算法视频公开课:[手把手带你入门动态规划 | leetcode509.斐波那契数](https://www.bilibili.com/video/BV1f5411K7mo),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[手把手带你入门动态规划 | leetcode509.斐波那契数](https://www.bilibili.com/video/BV1f5411K7mo),相信结合视频在看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -278,7 +278,7 @@ class Solution:
return self.fib(n - 1) + self.fib(n - 2) return self.fib(n - 1) + self.fib(n - 2)
``` ```
### Go ### Go
```Go ```Go
func fib(n int) int { func fib(n int) int {
if n < 2 { if n < 2 {
@ -479,3 +479,4 @@ public class Solution
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -152,8 +152,7 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
public class Solution { public class Solution {
@ -175,8 +174,7 @@ public class Solution {
} }
``` ```
### Python
Python
```python ```python
class Solution: class Solution:
@ -193,7 +191,7 @@ class Solution:
return dp[0][-1] return dp[0][-1]
``` ```
Go ### Go
```Go ```Go
func longestPalindromeSubseq(s string) int { func longestPalindromeSubseq(s string) int {
@ -222,7 +220,7 @@ func longestPalindromeSubseq(s string) int {
} }
``` ```
Javascript ### Javascript
```javascript ```javascript
const longestPalindromeSubseq = (s) => { const longestPalindromeSubseq = (s) => {
@ -247,7 +245,7 @@ const longestPalindromeSubseq = (s) => {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function longestPalindromeSubseq(s: string): number { function longestPalindromeSubseq(s: string): number {
@ -281,3 +279,4 @@ function longestPalindromeSubseq(s: string): number {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -41,9 +41,9 @@
* 硬币种类不超过 500 种 * 硬币种类不超过 500 种
* 结果符合 32 位符号整数 * 结果符合 32 位符号整数
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[装满背包有多少种方法?组合与排列有讲究!| LeetCode518.零钱兑换II](https://www.bilibili.com/video/BV1KM411k75j/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[装满背包有多少种方法?组合与排列有讲究!| LeetCode518.零钱兑换II](https://www.bilibili.com/video/BV1KM411k75j/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
@ -202,8 +202,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
class Solution { class Solution {
public int change(int amount, int[] coins) { public int change(int amount, int[] coins) {
@ -242,7 +242,7 @@ class Solution {
} }
``` ```
Python ### Python
```python ```python
@ -260,7 +260,8 @@ class Solution:
Go ### Go
```go ```go
func change(amount int, coins []int) int { func change(amount int, coins []int) int {
// 定义dp数组 // 定义dp数组
@ -280,7 +281,8 @@ func change(amount int, coins []int) int {
} }
``` ```
Rust: ### Rust:
```rust ```rust
impl Solution { impl Solution {
pub fn change(amount: i32, coins: Vec<i32>) -> i32 { pub fn change(amount: i32, coins: Vec<i32>) -> i32 {
@ -297,7 +299,8 @@ impl Solution {
} }
``` ```
Javascript ### Javascript
```javascript ```javascript
const change = (amount, coins) => { const change = (amount, coins) => {
let dp = Array(amount + 1).fill(0); let dp = Array(amount + 1).fill(0);
@ -313,7 +316,7 @@ const change = (amount, coins) => {
} }
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function change(amount: number, coins: number[]): number { function change(amount: number, coins: number[]): number {
@ -328,7 +331,7 @@ function change(amount: number, coins: number[]): number {
}; };
``` ```
Scala: ### Scala:
```scala ```scala
object Solution { object Solution {
@ -349,4 +352,3 @@ object Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -17,9 +17,9 @@
* 解释: 第一步将"sea"变为"ea",第二步将"eat"变为"ea" * 解释: 第一步将"sea"变为"ea",第二步将"eat"变为"ea"
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课[动态规划之子序列,还是为了编辑距离做铺垫 | LeetCode583.两个字符串的删除操(https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[LeetCode583.两个字符串的删除操](https://www.bilibili.com/video/BV1we4y157wB/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -143,8 +143,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
// dp数组中存储word1和word2最长相同子序列的长度 // dp数组中存储word1和word2最长相同子序列的长度
class Solution { class Solution {
@ -215,8 +215,8 @@ class Solution {
} }
``` ```
### Python
Python
```python ```python
class Solution: class Solution:
def minDistance(self, word1: str, word2: str) -> int: def minDistance(self, word1: str, word2: str) -> int:
@ -234,7 +234,8 @@ class Solution:
return dp[-1][-1] return dp[-1][-1]
``` ```
Go ### Go
```go ```go
func minDistance(word1 string, word2 string) int { func minDistance(word1 string, word2 string) int {
dp := make([][]int, len(word1)+1) dp := make([][]int, len(word1)+1)
@ -267,7 +268,8 @@ func min(a, b int) int {
return b return b
} }
``` ```
Javascript ### Javascript
```javascript ```javascript
// 方法一 // 方法一
var minDistance = (word1, word2) => { var minDistance = (word1, word2) => {
@ -309,7 +311,7 @@ var minDistance = function (word1, word2) {
}; };
``` ```
TypeScript ### TypeScript
> dp版本一 > dp版本一

View File

@ -26,11 +26,13 @@
提示:输入的字符串长度不会超过 1000 。 提示:输入的字符串长度不会超过 1000 。
## 暴力解法 ## 思路
### 暴力解法
两层for循环遍历区间起始位置和终止位置然后还需要一层遍历判断这个区间是不是回文。所以时间复杂度O(n^3) 两层for循环遍历区间起始位置和终止位置然后还需要一层遍历判断这个区间是不是回文。所以时间复杂度O(n^3)
## 动态规划 ### 动态规划
动规五部曲: 动规五部曲:
@ -187,7 +189,7 @@ public:
* 时间复杂度O(n^2) * 时间复杂度O(n^2)
* 空间复杂度O(n^2) * 空间复杂度O(n^2)
## 双指针法 ### 双指针法
动态规划的空间复杂度是偏高的,我们再看一下双指针法。 动态规划的空间复杂度是偏高的,我们再看一下双指针法。
@ -231,7 +233,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java ### Java
动态规划: 动态规划:
@ -337,7 +339,7 @@ class Solution {
} }
``` ```
Python ### Python
> 动态规划: > 动态规划:
```python ```python
@ -390,7 +392,8 @@ class Solution:
return res return res
``` ```
Go ### Go
```Go ```Go
func countSubstrings(s string) int { func countSubstrings(s string) int {
res:=0 res:=0
@ -416,7 +419,8 @@ func countSubstrings(s string) int {
} }
``` ```
Javascript ### Javascript
> 动态规划 > 动态规划
```javascript ```javascript
const countSubstrings = (s) => { 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 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -29,7 +29,7 @@
## 算法公开课 ## 算法公开课
**代码随想录算法视频公开课[动态规划之子序列问题,重点在于连续!| LeetCode674.最长连续递增序列](https://www.bilibili.com/video/BV1bD4y1778v)相信结合视频再看本篇题解更有助于大家对本题的理解**。 **[代码随想录算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之子序列问题,重点在于连续!| LeetCode674.最长连续递增序列](https://www.bilibili.com/video/BV1bD4y1778v)相信结合视频再看本篇题解更有助于大家对本题的理解**。
## 思路 ## 思路
@ -157,8 +157,7 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
> 动态规划: > 动态规划:
```java ```java
@ -207,7 +206,7 @@ public static int findLengthOfLCIS(int[] nums) {
} }
``` ```
Python ### Python
DP DP
```python ```python
@ -261,7 +260,8 @@ class Solution:
return result return result
``` ```
Go ### Go
> 动态规划: > 动态规划:
```go ```go
func findLengthOfLCIS(nums []int) int { func findLengthOfLCIS(nums []int) int {
@ -302,7 +302,8 @@ func findLengthOfLCIS(nums []int) int {
} }
``` ```
Rust: ### Rust:
```rust ```rust
pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 { pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
if nums.is_empty() { if nums.is_empty() {
@ -320,7 +321,7 @@ pub fn find_length_of_lcis(nums: Vec<i32>) -> i32 {
} }
``` ```
Javascript ### Javascript
> 动态规划: > 动态规划:
```javascript ```javascript
@ -363,7 +364,7 @@ const findLengthOfLCIS = (nums) => {
}; };
``` ```
TypeScript ### TypeScript
> 动态规划: > 动态规划:
@ -409,3 +410,4 @@ function findLengthOfLCIS(nums: number[]): number {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -32,9 +32,9 @@
* 0 < prices[i] < 50000. * 0 < prices[i] < 50000.
* 0 <= fee < 50000. * 0 <= fee < 50000.
# 算法公开课 ## 算法公开课
**代码随想录算法视频公开课[动态规划来决定最佳时机,这次含手续费!| LeetCode714.买卖股票的最佳时机含手续费](https://www.bilibili.com/video/BV1z44y1Z7UR)相信结合视频再看本篇题解更有助于大家对本题的理解**。 **[代码随想录算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划来决定最佳时机,这次含手续费!| LeetCode714.买卖股票的最佳时机含手续费](https://www.bilibili.com/video/BV1z44y1Z7UR)相信结合视频再看本篇题解更有助于大家对本题的理解**。
## 思路 ## 思路
@ -97,8 +97,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
/** /**
* 卖出时支付手续费 * 卖出时支付手续费
@ -173,9 +173,9 @@ class Solution {
} }
} }
``` ```
``` ### python
Python
```python ```python
class Solution: class Solution:
def maxProfit(self, prices: List[int], fee: int) -> int: def maxProfit(self, prices: List[int], fee: int) -> int:
@ -188,7 +188,8 @@ class Solution:
return max(dp[-1][0], dp[-1][1]) return max(dp[-1][0], dp[-1][1])
``` ```
Go ### Go
```go ```go
// 买卖股票的最佳时机含手续费 动态规划 // 买卖股票的最佳时机含手续费 动态规划
// 时间复杂度O(n) 空间复杂度O(n) // 时间复杂度O(n) 空间复杂度O(n)
@ -211,7 +212,8 @@ func max(a, b int) int {
} }
``` ```
Javascript ### Javascript
```javascript ```javascript
const maxProfit = (prices,fee) => { const maxProfit = (prices,fee) => {
let dp = Array.from(Array(prices.length), () => Array(2).fill(0)); let dp = Array.from(Array(prices.length), () => Array(2).fill(0));
@ -224,7 +226,7 @@ const maxProfit = (prices,fee) => {
} }
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function maxProfit(prices: number[], fee: number): number { function maxProfit(prices: number[], fee: number): number {
@ -245,8 +247,9 @@ function maxProfit(prices: number[], fee: number): number {
}; };
``` ```
Rust: ### Rust:
**贪心** **贪心**
```Rust ```Rust
impl Solution { impl Solution {
pub fn max_profit(prices: Vec<i32>, fee: i32) -> i32 { pub fn max_profit(prices: Vec<i32>, fee: i32) -> i32 {

View File

@ -25,9 +25,7 @@
## 算法公开课 ## 算法公开课
**代码随想录算法视频公开课[动态规划之子序列问题想清楚DP数组的定义 | LeetCode718.最长重复子数组](https://www.bilibili.com/video/BV178411H7hV)相信结合视频再看本篇题解更有助于大家对本题的理解**。 **[代码随想录算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之子序列问题想清楚DP数组的定义 | LeetCode718.最长重复子数组](https://www.bilibili.com/video/BV178411H7hV)相信结合视频再看本篇题解更有助于大家对本题的理解**。
## 思路 ## 思路
@ -126,7 +124,7 @@ public:
* 时间复杂度O(n × m)n 为A长度m为B长度 * 时间复杂度O(n × m)n 为A长度m为B长度
* 空间复杂度O(n × m) * 空间复杂度O(n × m)
## 滚动数组 ### 滚动数组
在如下图中 在如下图中
@ -257,8 +255,8 @@ class Solution {
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
// 版本一 // 版本一
class Solution { class Solution {
@ -300,7 +298,7 @@ class Solution {
} }
``` ```
Python ### Python
2维DP 2维DP
```python ```python
@ -395,7 +393,8 @@ class Solution:
``` ```
Go ### Go
```Go ```Go
func findLength(A []int, B []int) int { func findLength(A []int, B []int) int {
m, n := len(A), len(B) 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 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -37,9 +37,9 @@
* cost[i] 将会是一个整型数据,范围为 [0, 999] 。 * cost[i] 将会是一个整型数据,范围为 [0, 999] 。
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划开更了!| LeetCode746. 使用最小花费爬楼梯](https://www.bilibili.com/video/BV16G411c7yZ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划开更了!| LeetCode746. 使用最小花费爬楼梯](https://www.bilibili.com/video/BV16G411c7yZ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
----------- -----------
@ -523,3 +523,4 @@ public class Solution
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -19,7 +19,7 @@
## 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划之子序列问题,换汤不换药 | LeetCode1035.不相交的线](https://www.bilibili.com/video/BV1h84y1x7MP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划之子序列问题,换汤不换药 | LeetCode1035.不相交的线](https://www.bilibili.com/video/BV1h84y1x7MP),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -82,8 +82,8 @@ public:
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
class Solution { class Solution {
public int maxUncrossedLines(int[] nums1, int[] nums2) { public int maxUncrossedLines(int[] nums1, int[] nums2) {
@ -106,7 +106,8 @@ Java
} }
``` ```
Python ### Python
```python ```python
class Solution: class Solution:
def maxUncrossedLines(self, A: List[int], B: List[int]) -> int: def maxUncrossedLines(self, A: List[int], B: List[int]) -> int:
@ -120,8 +121,7 @@ class Solution:
return dp[-1][-1] return dp[-1][-1]
``` ```
### Go:
Golang:
```go ```go
func maxUncrossedLines(A []int, B []int) int { func maxUncrossedLines(A []int, B []int) int {
@ -152,7 +152,7 @@ func max(a, b int) int {
} }
``` ```
Rust: ### Rust:
```rust ```rust
pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 { pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
@ -173,7 +173,7 @@ pub fn max_uncrossed_lines(nums1: Vec<i32>, nums2: Vec<i32>) -> i32 {
} }
``` ```
JavaScript ### JavaScript
```javascript ```javascript
const maxUncrossedLines = (nums1, nums2) => { const maxUncrossedLines = (nums1, nums2) => {
@ -196,7 +196,7 @@ const maxUncrossedLines = (nums1, nums2) => {
}; };
``` ```
TypeScript ### TypeScript
```typescript ```typescript
function maxUncrossedLines(nums1: number[], nums2: number[]): number { function maxUncrossedLines(nums1: number[], nums2: number[]): number {
@ -224,3 +224,4 @@ function maxUncrossedLines(nums1: number[], nums2: number[]): number {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -35,9 +35,9 @@
* 1 <= stones.length <= 30 * 1 <= stones.length <= 30
* 1 <= stones[i] <= 1000 * 1 <= stones[i] <= 1000
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[这个背包最多能装多少LeetCode1049.最后一块石头的重量II](https://www.bilibili.com/video/BV14M411C7oV/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[这个背包最多能装多少LeetCode1049.最后一块石头的重量II](https://www.bilibili.com/video/BV14M411C7oV/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -341,7 +341,7 @@ func max(a, b int) int {
} }
``` ```
### JavaScript ### JavaScript:
```javascript ```javascript
/** /**
@ -364,7 +364,7 @@ var lastStoneWeightII = function (stones) {
}; };
``` ```
### C ### C:
```c ```c
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b))
@ -413,7 +413,7 @@ function lastStoneWeightII(stones: number[]): number {
}; };
``` ```
### Scala ### Scala:
滚动数组: 滚动数组:
```scala ```scala
@ -455,7 +455,7 @@ object Solution {
} }
``` ```
### Rust ### Rust:
```rust ```rust
impl Solution { impl Solution {
@ -477,3 +477,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -39,7 +39,7 @@
## 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划子序列问题经典题目 | LeetCode1143.最长公共子序列](https://www.bilibili.com/video/BV1ye4y1L7CQ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划子序列问题经典题目 | LeetCode1143.最长公共子序列](https://www.bilibili.com/video/BV1ye4y1L7CQ),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -136,7 +136,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java ### Java
```java ```java
/* /*
@ -207,8 +207,9 @@ class Solution {
} }
``` ```
Python ### Python
2维DP 2维DP
```python ```python
class Solution: class Solution:
def longestCommonSubsequence(self, text1: str, text2: str) -> int: def longestCommonSubsequence(self, text1: str, text2: str) -> int:
@ -252,7 +253,8 @@ class Solution:
``` ```
Go ### Go
```Go ```Go
func longestCommonSubsequence(text1 string, text2 string) int { func longestCommonSubsequence(text1 string, text2 string) int {
t1 := len(text1) t1 := len(text1)
@ -283,7 +285,8 @@ func max(a,b int)int {
``` ```
Javascript ### JavaScript
```javascript ```javascript
const longestCommonSubsequence = (text1, text2) => { const longestCommonSubsequence = (text1, text2) => {
let dp = Array.from(Array(text1.length+1), () => Array(text2.length+1).fill(0)); 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 ```typescript
function longestCommonSubsequence(text1: string, text2: string): number { function longestCommonSubsequence(text1: string, text2: string): number {
@ -326,7 +329,8 @@ function longestCommonSubsequence(text1: string, text2: string): number {
}; };
``` ```
Rust: ### Rust:
```rust ```rust
pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
let (n, m) = (text1.len(), text2.len()); let (n, m) = (text1.len(), text2.len());
@ -353,3 +357,4 @@ pub fn longest_common_subsequence(text1: String, text2: String) -> i32 {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

249
problems/qita/join.md Normal file
View File

@ -0,0 +1,249 @@
# 如何在Github上提交PRpull request
* 如何提交代码
* 合入不规范
* 提交信息不规范
* Markdown 代码格式
* pull request里的commit数量
* 代码注释
* 说明具体是哪种方法
* 代码规范
* 代码逻辑
* 处理冲突
以下在 [https://github.com/youngyangyang04/leetcode-master](https://github.com/youngyangyang04/leetcode-master) 上提交pr为为例
## 如何合入代码
首先来说一说如何合入代码不少录友还不太会使用github所以这里也做一下科普。
我特意申请一个新的Github账号给大家做一个示范。
需要强调一下一个commit就只更新一道题目不要很多题目一起放在一个commit里那样就很乱。
首先LeetCode-Master每天都有更新如何保持你fork到自己的仓库是最新的版本呢。
点击这里Fetch upstream。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20230721172815.png' width=500 alt=''></img></div>
点击之后,这里就会显示最新的信息了
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210516213032568.png' width=500 alt=''></img></div>
注意这时是你的远端仓库为最新版本本地还不是最新的本地要git pull一下。
基于最新的版本,大家在去提交代码。
如何提交代码呢首先把自己的代码提交到自己的fork的远端仓库中然后open pull request如图
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210516215102296.png' width=500 alt=''></img></div>
点击 open pull request之后就是如下画面一个pull request有多个commit。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210516215646937.png' width=500 alt=''></img></div>
然后就是给pull request 添加备注pull request是对本次commit的一个总结。如果一个pull request就一个commit那么就和commit的备注保持一次。 然后点击 create pull request 就可以了
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210516220219891.png' width=500 alt=''></img></div>
此时你就提交成功了我会在项目中的pull requests 处理列表里看到你的请求。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210516220502485.png' width=500 alt=''></img></div>
然后如果你发现自己的代码没有合入多半是有问题如果有问题都有会在pull request里给出留言的
## 注意事项
### 提交信息不规范
大家提交代码的时候有两个地方需要写备注一个是commit一个是pull requestpull request包好多个commit。
commit 说清楚本文件多了哪些修改而pull request则是对本次合入的所有commit做一个总结性描述。
commit备注举例添加Rust python3那么commit备注就是添加0001两数之和 Rust python3 版本
而pull request 如果只有一个commit那么就也是添加0001两数之和 Rust python3 版本
如果是多个commit 则把本次commit都描述一遍。
### Markdown 语法
关于 Markdown 代码格式,例如 添加C++代码,需要有代码块语法
\`\`\`C++
C++代码
\`\`\`
例如这个commit在添加java代码的时候就直接添加代码
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210512141514272.png' width=500 alt=''></img></div>
正确的格式应该是这样:
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210513101029336.png' width=500 alt=''></img></div>
一般发现问题,我也会在代码中给出评论:
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/2021051309401135.png' width=500 alt=''></img></div>
这样大家也可以学习一些 提交代码的规范方面的知识
有的录友 是添加的代码块语法,但没有标记是哪种语言,这样的话 代码就不会针对某种语言高亮显示了,也比较影响阅读,例如:
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/2021051214212374.png' width=500 alt=''></img></div>
提交python代码的话要注释好是python2还是python3
例如这样:
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210513174147165.png' width=500 alt=''></img></div>
当然python2的话只这么写就行
\`\`\`python
python代码
\`\`\`
### pull request里的commit数量
有的录友是一个pull request 里有很多commit 一个commit是一道题目的代码
有的录友是一个pull request 里有有一个commit。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210512221535670.png' width=500 alt=''></img></div>
其实如果大家是平时一天写了两三道题目的话那么分三个commit一个pull request提交上来就行。
一个pull request 一个commit也可以这样大家就会麻烦一点。
但注意一个pull request也不要放太多的commit一旦有一道题目代码不合格我没有合入就这个pull request里影响其他所有代码的合入了。
### 代码注释
提交的代码最好要有注释,这样也方便读者理解。
例如这位录友在提交Java代码的时候按照题解的意思对Java版本的代码进行的注释这就很棒👍
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210512212151438.png' width=500 alt=''></img></div>
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210513101321112.png' width=500 alt=''></img></div>
当然如果大家感觉 已有的代码 不符合以上要求的话,例如 代码思路不够清晰不够规范,注释不够友好,依然欢迎提交优化代码,要记得详细注释哦。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210516082342756.png' width=500 alt=''></img></div>
### 说明具体是哪种方法
有的题解有两种甚至三四种解法,在添加代码的时候,注释上也清楚具体是哪一种方法的版本。
下面这位录友做的就很好
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210512221951251.png' width=500 alt=''></img></div>
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210513101551819.png' width=500 alt=''></img></div>
有的题解是一起给出了多道题目的讲解例如项目中0102.二叉树的层序遍历.md 中有八道题目,那么大家添加代码的时候 应该在代码注释上,或者 直接写上 是哪个题目的代码。
### 代码规范
大家提交代码要规范,当然代码可以在力扣上运行通过是最基本的。
虽然我主张没有绝对正确的代码风格但既然是给LeetCode-Master提交代码尽量遵循Google编程规范。
经常看我的代码的录友应该都知道,我的代码格严格按照 Google C++ 编程规范来的,这样看上去会比较整洁。
大家提交代码的时候遇到规范性问题,例如哪里应该由空格,哪里没有空格,可以参考我的代码来。
有一位录友在提交代码的时候会把之前的代码 做一下规范性的调整,这就很棒。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210514093012603.png' width=500 alt=''></img></div>
**代码规范从你我做起!**
### 代码逻辑
**提交的代码要按照题解思路来写**
虽然大家自己发挥想象空间是好的,但是题解还是要一脉相承,读者看完题解,发现代码和题解不是一个思路的话,那和重新读代码有啥区别了。
所以和题解不是一个思路的代码,除非详细注释了自己的思路 或者 写一段自己代码的描述说明思路和优化的地方,否则我就不会通过合入了哈。
大家的代码 最好也将关键地方放上注释,这样有助于别人快速理解你的代码。
### 处理冲突
在合入的过程中还要处理冲突的代码, 理解大家代码的思路,解决冲突,然后在力扣提交一下,确保是没问题。
例如同一道题目, 一位录友提交了, 我还没处理如何,另一位录友也对这道题也提交了代码,这样就会发生冲突
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210514092248192.png' width=500 alt=''></img></div>
大家提交代码的热情太高了,我有时候根本处理不过来,但我必须当天处理完,否则第二天代码冲突会越来越多。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210514091457392.png' width=500 alt=''></img></div>
一天晚分别有两位录友提交了 30多道 java代码全部冲突解决冲突处理的我脖子疼[哭]
那么在处理冲突的时候 保留谁的代码,删点谁的代码呢?
我一定是看谁 代码逻辑和题解一致,代码风格好,注释友好,就保留谁的。
所以例如当你想提交Java代码的时候即使发现该题解已经有Java版本了只要你的代码写的好一样可以提交我评审合格一样可以合入代码库。
### 不要做额外修改
确保这种额外文件不要提交。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210514093430534.png' width=500 alt=''></img></div>
还有添加不同方法的时候,直接用正文格式写,哪种方法就可以了,不要添加目录 ,例如这样,这样整篇文章目录结构就有影响了。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210513102640556.png' width=500 alt=''></img></div>
前面不要加 `## 前序遍历(迭代法)`,直接写`前序遍历(迭代法)`就可以了。
当然这里也没有给代码块标记上对应的语言,应该是
\`\`\` Go
Go语言代码
\`\`\`
## 对代码保持敬畏
有的录友甚至提交的代码并不是本题的代码,虽然我是鼓励大家提交代码的,但是大家贡献代码的时候也要对 自己的代码有敬畏之心,自己的代码是要给很多读者看的。
* 代码运行无误
* 写的够不够简洁
* 注释清不清晰
* 备注规不规范
这也是培养大家以后协调工作的一种能力。
## 优化
目前 leetcode-master中大部分题解已经补充了其他语言但如果你发现了可以优化的地方依然可以提交PR来优化。
甚至发现哪里有语病也欢迎提交PR来修改例如下面就是把【下表】 纠正为【下标】
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210811144337.png' width=500 alt=''></img></div>
不用非要写出牛逼的代码才能提交PR只要发现 文章中有任何问题或者错别字都欢迎提交PR成为contributor。
<div align="center"><img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20210927113149.png' width=500 alt=''></img></div>
## 特别注意
git add之前要git diff 查看一下,本次提交所修改的代码是不是 自己修改的,是否 误删,或者误加的文件。
提交代码不要使用git push -f 这种命令,要足够了解 -f 意味着什么。

View File

@ -1,15 +0,0 @@
优化已有代码
![](https://code-thinking-1253855093.file.myqcloud.com/pics/20210821161813.png)
**push代码之前 一定要 先pull最新代码**否则提交的pr可能会有删除其他录友代码的操作。
一个pr 不要修改过多文件,因为一旦有一个 文件修改有问题,就不能合入,影响其他文件的合入了。
git add之前要git diff 查看一下,本次提交所修改的代码是不是 自己修改的,是否 误删,或者误加的文件。
提交代码不要使用git push -f 这种命令,要足够了解 -f 意味着什么。
不用非要写出牛逼的代码才能提交PR只要发现 文章中有任何问题或者错别字都欢迎提交PR成为contributor。
![](https://code-thinking-1253855093.file.myqcloud.com/pics/20210927113149.png)

View File

@ -163,8 +163,8 @@ else {
## 其他语言版本 ## 其他语言版本
### Java
Java
```java ```java
class Solution { class Solution {
public int minDistance(String word1, String word2) { public int minDistance(String word1, String word2) {
@ -193,11 +193,6 @@ class Solution {
} }
``` ```
Python
Go
@ -205,3 +200,4 @@ Go
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -1,6 +1,8 @@
# 力扣上如何自己构造二叉树输入用例? # 力扣上如何自己构造二叉树输入用例?
**这里给大家推荐ACM模式练习网站**[kamacoder.com](https://kamacoder.com)把上面的题目刷完ACM模式就没问题了。
经常有录友问二叉树的题目中输入用例在ACM模式下应该怎么构造呢 经常有录友问二叉树的题目中输入用例在ACM模式下应该怎么构造呢
力扣上的题目,输入用例就给了一个数组,怎么就能构造成二叉树呢? 力扣上的题目,输入用例就给了一个数组,怎么就能构造成二叉树呢?

View File

@ -5,6 +5,10 @@
什么是ACM输入模式呢 就是自己构造输入数据格式把要需要处理的容器填充好OJ不会给你任何代码包括include哪些函数都要自己写最后也要自己控制返回数据的格式。 什么是ACM输入模式呢 就是自己构造输入数据格式把要需要处理的容器填充好OJ不会给你任何代码包括include哪些函数都要自己写最后也要自己控制返回数据的格式。
**这里给大家推荐ACM模式练习网站**[kamacoder.com](https://kamacoder.com)把上面的题目刷完ACM模式就没问题了。
而力扣上是核心代码模式,就是把要处理的数据都已经放入容器里,可以直接写逻辑,例如这样: 而力扣上是核心代码模式,就是把要处理的数据都已经放入容器里,可以直接写逻辑,例如这样:
```CPP ```CPP

View File

@ -29,7 +29,7 @@
这里我简单说一说规范问题。 这里我简单说一说规范问题。
**权威的C++规范以Google为主**,我给大家下载了一份中文版本,在公众号「代码随想录」后台回复:googlec++编程规范,就可以领取。(涉及到微信后台的回复,没更改) **权威的C++规范以Google为主**,我给大家下载了一份中文版本,在公众号「代码随想录」后台回复:编程规范,就可以领取。
**具体的规范要以自己团队风格为主**,融入团队才是最重要的。 **具体的规范要以自己团队风格为主**,融入团队才是最重要的。

View File

@ -36,7 +36,7 @@
* 微众银行(总部深圳) * 微众银行(总部深圳)
* 招银科技(总部深圳) * 招银科技(总部深圳)
* 平安系列(平安科技、平安寿险、平安产险、平安金融、平安好医生等) * 平安系列(平安科技、平安寿险、平安产险、平安金融、平安好医生等)
* Shopee东南亚最大的电商平台,最近发展势头非常强劲 * Shopee21年有裁员风波
* 有赞(深圳) * 有赞(深圳)
* 迅雷(总部深圳) * 迅雷(总部深圳)
* 金蝶(总部深圳) * 金蝶(总部深圳)

View File

@ -471,21 +471,10 @@ public:
「代码随想录」值得推荐给身边每一位学习算法的朋友同学们,关注后都会发现相见恨晚! 「代码随想录」值得推荐给身边每一位学习算法的朋友同学们,关注后都会发现相见恨晚!
## 其他语言版本
Java
Python
Go
<p align="center"> <p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -136,3 +136,4 @@
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -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 @@
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -1,3 +1,4 @@
# 本周小结!(动态规划系列一)
这周我们正式开始动态规划的学习! 这周我们正式开始动态规划的学习!

View File

@ -1,3 +1,4 @@
# 本周小结!(动态规划系列二)
## 周一 ## 周一

View File

@ -1,3 +1,4 @@
# 本周小结!(动态规划系列六)
本周我们主要讲解了打家劫舍系列这个系列也是dp解决的经典问题那么来看看我们收获了哪些呢一起来回顾一下吧。 本周我们主要讲解了打家劫舍系列这个系列也是dp解决的经典问题那么来看看我们收获了哪些呢一起来回顾一下吧。

View File

@ -1,3 +1,4 @@
# 本周小结!(动态规划系列七)
本周的主题就是股票系列,来一起回顾一下吧 本周的主题就是股票系列,来一起回顾一下吧

View File

@ -106,3 +106,4 @@
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -8,8 +8,11 @@
# 动态规划01背包理论基础 # 动态规划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] 。**每件物品只能用一次**,求解将哪些物品装入背包里物品价值总和最大。 有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数组打印出来对比一下和自己推导的有什么差异很快就可以发现问题了。 主要就是自己没有动手推导一下dp数组的演变过程如果推导明白了代码写出来就算有问题只要把dp数组打印出来对比一下和自己推导的有什么差异很快就可以发现问题了。
## 完整c++测试代码
```cpp ```cpp
void test_2_wei_bag_problem1() { void test_2_wei_bag_problem1() {
vector<int> weight = {1, 3, 4}; vector<int> weight = {1, 3, 4};
@ -275,7 +275,7 @@ int main() {
## 其他语言版本 ## 其他语言版本
### java ### Java
```java ```java
public class BagProblem { public class BagProblem {
@ -396,7 +396,8 @@ public class BagProblem {
``` ```
### python ### Python
无参数版 无参数版
```python ```python
def test_2_wei_bag_problem1(): def test_2_wei_bag_problem1():
@ -456,8 +457,7 @@ if __name__ == "__main__":
``` ```
### Go
### go
```go ```go
func test_2_wei_bag_problem1(weight, value []int, bagweight int) int { func test_2_wei_bag_problem1(weight, value []int, bagweight int) int {
@ -498,7 +498,7 @@ func main() {
} }
``` ```
### javascript ### Javascript
```js ```js
function testWeightBagProblem (weight, value, size) { function testWeightBagProblem (weight, value, size) {

View File

@ -3,10 +3,13 @@
<img src="../pics/训练营.png" width="1000"/> <img src="../pics/训练营.png" width="1000"/>
</a> </a>
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p> <p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
# 动态规划01背包理论基础滚动数组 # 动态规划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背包。 昨天[动态规划关于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 ```CPP
void test_1_wei_bag_problem() { void test_1_wei_bag_problem() {
vector<int> weight = {1, 3, 4}; vector<int> weight = {1, 3, 4};
@ -318,7 +319,7 @@ func main() {
} }
``` ```
### javaScript ### JavaScript
```js ```js
@ -459,3 +460,4 @@ fn test_wei_bag_problem2() {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -144,8 +144,7 @@ int main() {
## 其他语言版本 ## 其他语言版本
### Java
Java
```Java ```Java
public void testMultiPack1(){ public void testMultiPack1(){
@ -192,7 +191,7 @@ public void testMultiPack2(){
} }
``` ```
Python ### Python
改变物品数量为01背包格式无参版 改变物品数量为01背包格式无参版
```python ```python
@ -315,7 +314,7 @@ if __name__ == "__main__":
test_multi_pack(weight, value, nums, bagWeight) test_multi_pack(weight, value, nums, bagWeight)
``` ```
Go ### Go
```go ```go
package theory package theory
@ -406,7 +405,7 @@ func Test_multiplePack(t *testing.T) {
PASS PASS
``` ```
TypeScript ### TypeScript
> 版本一(改变数据源): > 版本一(改变数据源):
@ -469,3 +468,4 @@ testMultiPack();
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>

View File

@ -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] 。**每件物品都有无限个(也就是可以放入背包多次)**,求解将哪些物品装入背包里物品价值总和最大。 有N件物品和一个最多能背重量为W的背包。第i件物品的重量是weight[i]得到的价值是value[i] 。**每件物品都有无限个(也就是可以放入背包多次)**,求解将哪些物品装入背包里物品价值总和最大。
@ -113,8 +117,6 @@ for(int j = 0; j <= bagWeight; j++) { // 遍历背包容量
} }
``` ```
## C++测试代码
完整的C++测试代码如下: 完整的C++测试代码如下:
```CPP ```CPP
@ -181,7 +183,7 @@ int main() {
## 其他语言版本 ## 其他语言版本
Java ### Java
```java ```java
//先遍历物品,再遍历背包 //先遍历物品,再遍历背包
@ -221,9 +223,7 @@ private static void testCompletePackAnotherWay(){
Python ### Python
先遍历物品,再遍历背包(无参版) 先遍历物品,再遍历背包(无参版)
```python ```python
@ -299,7 +299,8 @@ if __name__ == "__main__":
``` ```
Go ### Go
```go ```go
// test_CompletePack1 先遍历物品, 在遍历背包 // test_CompletePack1 先遍历物品, 在遍历背包
@ -352,7 +353,8 @@ func main() {
fmt.Println(test_CompletePack2(weight, price, 4)) fmt.Println(test_CompletePack2(weight, price, 4))
} }
``` ```
Javascript: ### Javascript:
```Javascript ```Javascript
// 先遍历物品,再遍历背包容量 // 先遍历物品,再遍历背包容量
function test_completePack1() { function test_completePack1() {
@ -385,7 +387,7 @@ function test_completePack2() {
} }
``` ```
TypeScript ### TypeScript
```typescript ```typescript
// 先遍历物品,再遍历背包容量 // 先遍历物品,再遍历背包容量
@ -404,7 +406,7 @@ function test_CompletePack(): void {
test_CompletePack(); test_CompletePack();
``` ```
Scala: ### Scala:
```scala ```scala
// 先遍历物品,再遍历背包容量 // 先遍历物品,再遍历背包容量
@ -426,7 +428,7 @@ object Solution {
} }
``` ```
Rust: ### Rust:
```rust ```rust
impl Solution { impl Solution {
@ -468,3 +470,4 @@ fn test_complete_pack() {
<a href="https://programmercarl.com/other/kstar.html" target="_blank"> <a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>