Merge pull request #2212 from jinbudaily/master

更新 各章节 排版格式修复
This commit is contained in:
程序员Carl
2023-07-28 21:06:45 +08:00
committed by GitHub
35 changed files with 116 additions and 102 deletions

View File

@ -318,7 +318,7 @@ function twoSum(nums: number[], target: number): number[] {
}; };
``` ```
### php: ### PhP:
```php ```php
function twoSum(array $nums, int $target): array function twoSum(array $nums, int $target): array
@ -501,3 +501,4 @@ int* twoSum(int* nums, int numsSize, int target, int* returnSize){
<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,10 +152,10 @@ public:
## 相关题目推荐 ## 相关题目推荐
* 26.删除排序数组中的重复项 * [26.删除排序数组中的重复项](https://leetcode.cn/problems/remove-duplicates-from-sorted-array/)
* 283.移动零 * [283.移动零](https://leetcode.cn/problems/move-zeroes/)
* 844.比较含退格的字符串 * [844.比较含退格的字符串](https://leetcode.cn/problems/backspace-string-compare/)
* 977.有序数组的平方 * [977.有序数组的平方](https://leetcode.cn/problems/squares-of-a-sorted-array/)
## 其他语言版本 ## 其他语言版本
@ -444,3 +444,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

@ -16,11 +16,13 @@
- 输出: 6 - 输出: 6
- 解释:  连续子数组  [4,-1,2,1] 的和最大,为  6。 - 解释:  连续子数组  [4,-1,2,1] 的和最大,为  6。
# 视频讲解 ## 算法公开课
**《代码随想录》算法视频公开课:[贪心算法的巧妙需要慢慢体会LeetCode53. 最大子序和](https://www.bilibili.com/video/BV1aY4y1Z7ya),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[贪心算法的巧妙需要慢慢体会LeetCode53. 最大子序和](https://www.bilibili.com/video/BV1aY4y1Z7ya),相信结合视频在看本篇题解,更有助于大家对本题的理解**。
## 暴力解法 ## 思路
### 暴力解法
暴力解法的思路,第一层 for 就是设置起始位置,第二层 for 循环遍历数组寻找最大值 暴力解法的思路,第一层 for 就是设置起始位置,第二层 for 循环遍历数组寻找最大值
@ -48,7 +50,7 @@ public:
以上暴力的解法 C++勉强可以过,其他语言就不确定了。 以上暴力的解法 C++勉强可以过,其他语言就不确定了。
## 贪心解法 ### 贪心解法
**贪心贪的是哪里呢?** **贪心贪的是哪里呢?**
@ -104,7 +106,7 @@ public:
当然题目没有说如果数组为空,应该返回什么,所以数组为空的话返回啥都可以了。 当然题目没有说如果数组为空,应该返回什么,所以数组为空的话返回啥都可以了。
## 常见误区 ### 常见误区
误区一: 误区一:
@ -122,7 +124,7 @@ public:
其实并不会,因为还有一个变量 result 一直在更新 最大的连续和只要有更大的连续和出现result 就更新了,那么 result 已经把 4 更新了,后面 连续和变成 3也不会对最后结果有影响。 其实并不会,因为还有一个变量 result 一直在更新 最大的连续和只要有更大的连续和出现result 就更新了,那么 result 已经把 4 更新了,后面 连续和变成 3也不会对最后结果有影响。
## 动态规划 ### 动态规划
当然本题还可以用动态规划来做,在代码随想录动态规划章节我会详细介绍,如果大家想在想看,可以直接跳转:[动态规划版本详解](https://programmercarl.com/0053.%E6%9C%80%E5%A4%A7%E5%AD%90%E5%BA%8F%E5%92%8C%EF%BC%88%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%EF%BC%89.html#%E6%80%9D%E8%B7%AF) 当然本题还可以用动态规划来做,在代码随想录动态规划章节我会详细介绍,如果大家想在想看,可以直接跳转:[动态规划版本详解](https://programmercarl.com/0053.%E6%9C%80%E5%A4%A7%E5%AD%90%E5%BA%8F%E5%92%8C%EF%BC%88%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%EF%BC%89.html#%E6%80%9D%E8%B7%AF)

View File

@ -6,7 +6,7 @@
## 54.螺旋矩阵 # 54.螺旋矩阵
[力扣题目链接](https://leetcode.cn/problems/spiral-matrix/) [力扣题目链接](https://leetcode.cn/problems/spiral-matrix/)

View File

@ -688,7 +688,7 @@ public class Solution {
} }
``` ```
### Ruby#: ### Ruby:
```ruby ```ruby
def generate_matrix(n) def generate_matrix(n)
result = Array.new(n) { Array.new(n, 0) } result = Array.new(n) { Array.new(n, 0) }

View File

@ -50,9 +50,9 @@
* 1 <= m, n <= 100 * 1 <= m, n <= 100
* 题目数据保证答案小于等于 2 * 10^9 * 题目数据保证答案小于等于 2 * 10^9
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划中如何初始化很重要!| LeetCode62.不同路径](https://www.bilibili.com/video/BV1ve4y1x7Eu/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划中如何初始化很重要!| LeetCode62.不同路径](https://www.bilibili.com/video/BV1ve4y1x7Eu/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路

View File

@ -46,9 +46,9 @@
* 1 <= m, n <= 100 * 1 <= m, n <= 100
* obstacleGrid[i][j] 为 0 或 1 * obstacleGrid[i][j] 为 0 或 1
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,这次遇到障碍了| LeetCode63. 不同路径 II](https://www.bilibili.com/video/BV1Ld4y1k7c6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,这次遇到障碍了| LeetCode63. 不同路径 II](https://www.bilibili.com/video/BV1Ld4y1k7c6/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路

View File

@ -3,6 +3,7 @@
<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>
# 90.子集II # 90.子集II
[力扣题目链接](https://leetcode.cn/problems/subsets-ii/) [力扣题目链接](https://leetcode.cn/problems/subsets-ii/)

View File

@ -16,9 +16,9 @@
![](https://code-thinking-1253855093.file.myqcloud.com/pics/20210113161941835.png) ![](https://code-thinking-1253855093.file.myqcloud.com/pics/20210113161941835.png)
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划找到子状态之间的关系很重要!| LeetCode96.不同的二叉搜索树](https://www.bilibili.com/video/BV1eK411o7QA/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划找到子状态之间的关系很重要!| LeetCode96.不同的二叉搜索树](https://www.bilibili.com/video/BV1eK411o7QA/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路

View File

@ -433,7 +433,7 @@ class Solution {
} }
``` ```
### python: ### Python:
(版本一)先删除空白,然后整个反转,最后单词反转。 (版本一)先删除空白,然后整个反转,最后单词反转。
**因为字符串是不可变类型所以反转单词的时候需要将其转换成列表然后通过join函数再将其转换成列表所以空间复杂度不是O(1)** **因为字符串是不可变类型所以反转单词的时候需要将其转换成列表然后通过join函数再将其转换成列表所以空间复杂度不是O(1)**
@ -976,4 +976,3 @@ char * reverseWords(char * s){
<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

@ -529,4 +529,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

@ -197,7 +197,6 @@ class Solution {
} }
``` ```
## 其他语言版本
### Python ### Python
BFS solution BFS solution
```python ```python
@ -244,3 +243,4 @@ class Solution:
<img src="../pics/网站星球宣传海报.jpg" width="1000"/> <img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a> </a>
``` ```

View File

@ -3,6 +3,7 @@
<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>
# 283. 移动零:动态规划:一样的套路,再求一次完全平方数 # 283. 移动零:动态规划:一样的套路,再求一次完全平方数
[力扣题目链接](https://leetcode.cn/problems/move-zeroes/) [力扣题目链接](https://leetcode.cn/problems/move-zeroes/)

View File

@ -31,7 +31,7 @@
## 算法公开课 ## 算法公开课
**如果对回溯算法基础还不了解的话,我还特意录制了一期视频,[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[带你学透回溯算法(理论篇)](https://www.bilibili.com/video/BV1cy4y167mM/)** 可以结合题解和视频一起看,希望对大家理解回溯算法有所帮助。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[带你学透回溯算法(理论篇)](https://www.bilibili.com/video/BV1cy4y167mM/) ,相信结合视频再看本篇题解,更有助于大家对本题的理解。**
## 思路 ## 思路
@ -793,4 +793,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

@ -22,9 +22,9 @@
* 说明: 你可以假设 n 不小于 2 且不大于 58。 * 说明: 你可以假设 n 不小于 2 且不大于 58。
# 算法公开课 ## 算法公开课
**《代码随想录》算法视频公开课:[动态规划,本题关键在于理解递推公式!| LeetCode343. 整数拆分](https://www.bilibili.com/video/BV1Mg411q7YJ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[动态规划,本题关键在于理解递推公式!| LeetCode343. 整数拆分](https://www.bilibili.com/video/BV1Mg411q7YJ/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。
## 思路 ## 思路
@ -473,3 +473,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

@ -4,7 +4,7 @@
</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>
## 416. 分割等和子集 # 416. 分割等和子集
[力扣题目链接](https://leetcode.cn/problems/partition-equal-subset-sum/) [力扣题目链接](https://leetcode.cn/problems/partition-equal-subset-sum/)
@ -730,4 +730,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

@ -294,4 +294,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

@ -19,7 +19,7 @@
注意: 合并必须从两个树的根节点开始。 注意: 合并必须从两个树的根节点开始。
# 算法公开课 ## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[一起操作两个二叉树?有点懵!| LeetCode617.合并二叉树](https://www.bilibili.com/video/BV1m14y1Y7JK),相信结合视频在看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[一起操作两个二叉树?有点懵!| LeetCode617.合并二叉树](https://www.bilibili.com/video/BV1m14y1Y7JK),相信结合视频在看本篇题解,更有助于大家对本题的理解**。
@ -793,3 +793,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

@ -22,7 +22,7 @@
* 输出6 * 输出6
* 解释:答案不应该是 11 ,因为岛屿只能包含水平或垂直这四个方向上的 1 。 * 解释:答案不应该是 11 ,因为岛屿只能包含水平或垂直这四个方向上的 1 。
# 思路 ## 思路
注意题目中每座岛屿只能由**水平方向和/或竖直方向上**相邻的陆地连接形成。 注意题目中每座岛屿只能由**水平方向和/或竖直方向上**相邻的陆地连接形成。
@ -38,7 +38,7 @@
* [DFS理论基础](https://programmercarl.com/图论深搜理论基础.html) * [DFS理论基础](https://programmercarl.com/图论深搜理论基础.html)
* [BFS理论基础](https://programmercarl.com/图论广搜理论基础.html) * [BFS理论基础](https://programmercarl.com/图论广搜理论基础.html)
## DFS ### DFS
很多同学写dfs其实也是凭感觉来有的时候dfs函数中写终止条件才能过有的时候 dfs函数不写终止添加也能过 很多同学写dfs其实也是凭感觉来有的时候dfs函数中写终止条件才能过有的时候 dfs函数不写终止添加也能过
@ -134,7 +134,7 @@ public:
以上两种写法的区别,我在题解: [DFSBDF 你没注意的细节都给你列出来了LeetCode200. 岛屿数量](https://leetcode.cn/problems/number-of-islands/solution/by-carlsun-2-n72a/)做了详细介绍。 以上两种写法的区别,我在题解: [DFSBDF 你没注意的细节都给你列出来了LeetCode200. 岛屿数量](https://leetcode.cn/problems/number-of-islands/solution/by-carlsun-2-n72a/)做了详细介绍。
## BFS ### BFS
关于广度优先搜索,如果大家还不了解的话,看这里:[广度优先搜索精讲](https://programmercarl.com/图论广搜理论基础.html) 关于广度优先搜索,如果大家还不了解的话,看这里:[广度优先搜索精讲](https://programmercarl.com/图论广搜理论基础.html)
@ -188,9 +188,9 @@ public:
``` ```
# 其它语言版本 ## 其它语言版本
## Java ### Java
### DFS #### DFS
```java ```java
// DFS // DFS
class Solution { class Solution {
@ -236,7 +236,7 @@ class Solution {
``` ```
### BFS #### BFS
```java ```java
//BFS //BFS
class Solution { class Solution {
@ -290,7 +290,7 @@ class Solution {
} }
} }
``` ```
### DFS 優化(遇到島嶼後,就把他淹沒) #### DFS 優化(遇到島嶼後,就把他淹沒)
```java ```java
//这里使用深度优先搜索 DFS 来完成本道题目。我们使用 DFS 计算一个岛屿的面积,同时维护计算过的最大的岛屿面积。同时,为了避免对岛屿重复计算,我们在 DFS 的时候对岛屿进行 “淹没” 操作,即将岛屿所占的地方置为 0。 //这里使用深度优先搜索 DFS 来完成本道题目。我们使用 DFS 计算一个岛屿的面积,同时维护计算过的最大的岛屿面积。同时,为了避免对岛屿重复计算,我们在 DFS 的时候对岛屿进行 “淹没” 操作,即将岛屿所占的地方置为 0。
public int maxAreaOfIsland(int[][] grid) { public int maxAreaOfIsland(int[][] grid) {
@ -319,8 +319,8 @@ public int dfs(int[][] grid,int i,int j){
} }
``` ```
## Python ### Python
### BFS #### BFS
```python ```python
class Solution: class Solution:
def __init__(self): def __init__(self):
@ -359,7 +359,7 @@ class Solution:
self.count += 1 self.count += 1
queue.append((new_x, new_y)) queue.append((new_x, new_y))
``` ```
### DFS #### DFS
```python ```python
class Solution: class Solution:
def __init__(self): def __init__(self):
@ -394,3 +394,4 @@ 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

@ -150,8 +150,8 @@ public:
* [35.搜索插入位置](https://programmercarl.com/0035.搜索插入位置.html) * [35.搜索插入位置](https://programmercarl.com/0035.搜索插入位置.html)
* [34.在排序数组中查找元素的第一个和最后一个位置](https://programmercarl.com/0034.%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%92%8C%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E4%BD%8D%E7%BD%AE.html) * [34.在排序数组中查找元素的第一个和最后一个位置](https://programmercarl.com/0034.%E5%9C%A8%E6%8E%92%E5%BA%8F%E6%95%B0%E7%BB%84%E4%B8%AD%E6%9F%A5%E6%89%BE%E5%85%83%E7%B4%A0%E7%9A%84%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%92%8C%E6%9C%80%E5%90%8E%E4%B8%80%E4%B8%AA%E4%BD%8D%E7%BD%AE.html)
* 69.x 的平方根 * [69.x 的平方根](https://leetcode.cn/problems/sqrtx/)
* 367.有效的完全平方数 * [367.有效的完全平方数](https://leetcode.cn/problems/valid-perfect-square/)
@ -814,3 +814,4 @@ 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

@ -39,7 +39,7 @@
本题相对于[贪心算法122.买卖股票的最佳时机II](https://programmercarl.com/0122.买卖股票的最佳时机II.html)多添加了一个条件就是手续费 本题相对于[贪心算法122.买卖股票的最佳时机II](https://programmercarl.com/0122.买卖股票的最佳时机II.html)多添加了一个条件就是手续费
## 贪心算法 ### 贪心算法
[贪心算法122.买卖股票的最佳时机II](https://programmercarl.com/0122.买卖股票的最佳时机II.html)中使用贪心策略不用关心具体什么时候买卖只要收集每天的正利润最后稳稳的就是最大利润了 [贪心算法122.买卖股票的最佳时机II](https://programmercarl.com/0122.买卖股票的最佳时机II.html)中使用贪心策略不用关心具体什么时候买卖只要收集每天的正利润最后稳稳的就是最大利润了
@ -93,7 +93,7 @@ public:
大家也可以发现情况三那块代码是可以删掉的我是为了让代码表达清晰所以没有精简 大家也可以发现情况三那块代码是可以删掉的我是为了让代码表达清晰所以没有精简
## 动态规划 ### 动态规划
我在公众号代码随想录里将在下一个系列详细讲解动态规划所以本题解先给出我的C++代码带详细注释感兴趣的同学可以自己先学习一下 我在公众号代码随想录里将在下一个系列详细讲解动态规划所以本题解先给出我的C++代码带详细注释感兴趣的同学可以自己先学习一下
@ -364,3 +364,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

@ -149,7 +149,7 @@ public:
``` ```
# 总结 ## 总结
本题是比较基础的深度优先搜索模板题,这种有向图路径问题,最合适使用深搜,当然本题也可以使用广搜,但广搜相对来说就麻烦了一些,需要记录一下路径。 本题是比较基础的深度优先搜索模板题,这种有向图路径问题,最合适使用深搜,当然本题也可以使用广搜,但广搜相对来说就麻烦了一些,需要记录一下路径。
@ -159,7 +159,7 @@ public:
## 其他语言版本 ## 其他语言版本
Java ### Java
```Java ```Java
// 深度优先遍历 // 深度优先遍历
@ -190,7 +190,8 @@ class Solution {
} }
``` ```
Python ### Python
```python ```python
class Solution: class Solution:
def __init__(self): def __init__(self):
@ -216,9 +217,9 @@ class Solution:
self.path.pop() # 回溯 self.path.pop() # 回溯
``` ```
### 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

@ -29,7 +29,7 @@
* 输出: 4 * 输出: 4
* 解释: 没有0可以让我们变成1面积依然为 4。 * 解释: 没有0可以让我们变成1面积依然为 4。
# 思路 ## 思路
本题的一个暴力想法,应该是遍历地图尝试 将每一个 0 改成1然后去搜索地图中的最大的岛屿面积。 本题的一个暴力想法,应该是遍历地图尝试 将每一个 0 改成1然后去搜索地图中的最大的岛屿面积。
@ -219,9 +219,9 @@ public:
}; };
``` ```
# 其他语言版本 ## 其他语言版本
## Java ### Java
```Java ```Java
class Solution { class Solution {
@ -286,4 +286,3 @@ 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

@ -38,7 +38,7 @@
本文将给出 空间复杂度O(n)的栈模拟方法 以及空间复杂度是O(1)的双指针方法。 本文将给出 空间复杂度O(n)的栈模拟方法 以及空间复杂度是O(1)的双指针方法。
## 普通方法(使用栈的思路) ### 普通方法(使用栈的思路)
这道题目一看就是要使用栈的节奏,这种匹配(消除)问题也是栈的擅长所在,跟着一起刷题的同学应该知道,在[栈与队列:匹配问题都是栈的强项](https://programmercarl.com/1047.删除字符串中的所有相邻重复项.html),我就已经提过了一次使用栈来做类似的事情了。 这道题目一看就是要使用栈的节奏,这种匹配(消除)问题也是栈的擅长所在,跟着一起刷题的同学应该知道,在[栈与队列:匹配问题都是栈的强项](https://programmercarl.com/1047.删除字符串中的所有相邻重复项.html),我就已经提过了一次使用栈来做类似的事情了。
@ -100,7 +100,7 @@ public:
* 时间复杂度O(n + m) * 时间复杂度O(n + m)
* 空间复杂度O(n + m) * 空间复杂度O(n + m)
## 优化方法(从后向前双指针) ### 优化方法(从后向前双指针)
当然还可以有使用 O(1) 的空间复杂度来解决该问题。 当然还可以有使用 O(1) 的空间复杂度来解决该问题。
@ -289,7 +289,7 @@ class Solution {
} }
``` ```
### python ### Python
```python ```python
class Solution: class Solution:
@ -591,3 +591,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

@ -3,6 +3,7 @@
<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>
# 1791.找出星型图的中心节点 # 1791.找出星型图的中心节点
[题目链接](https://leetcode.cn/problems/find-center-of-star-graph/) [题目链接](https://leetcode.cn/problems/find-center-of-star-graph/)
@ -55,7 +56,7 @@ public:
return -1; return -1;
} }
}; };
``` ```
以上代码中没有使用 unordered_map因为遍历的时候开辟新空间会浪费时间而采用 vector这是 空间换时间的一种策略。 以上代码中没有使用 unordered_map因为遍历的时候开辟新空间会浪费时间而采用 vector这是 空间换时间的一种策略。

View File

@ -138,3 +138,4 @@ public:
<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

@ -200,4 +200,3 @@ 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

@ -142,7 +142,7 @@ class Solution {
} }
``` ```
### python: ### Python:
(版本一)使用切片 (版本一)使用切片
```python ```python
@ -338,7 +338,7 @@ func reverseString(_ s: inout [Character], startIndex: Int, endIndex: Int) {
``` ```
### PHP ### PHP
```php ```php
function reverseLeftWords($s, $n) { function reverseLeftWords($s, $n) {
@ -418,4 +418,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,7 +40,7 @@
好啦,我们再一起回顾一下,动态规划专题中我们都讲了哪些内容。 好啦,我们再一起回顾一下,动态规划专题中我们都讲了哪些内容。
## 动划基础 ## 动态规划基础
* [关于动态规划,你该了解这些!](https://programmercarl.com/动态规划理论基础.html) * [关于动态规划,你该了解这些!](https://programmercarl.com/动态规划理论基础.html)
* [动态规划:斐波那契数](https://programmercarl.com/0509.斐波那契数.html) * [动态规划:斐波那契数](https://programmercarl.com/0509.斐波那契数.html)
@ -136,4 +136,3 @@
<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

@ -9,6 +9,8 @@
-------------------------- --------------------------
# 本周小结!(回溯算法系列一)
## 周一 ## 周一
本周我们正式开始了回溯算法系列,那么首先当然是概述。 本周我们正式开始了回溯算法系列,那么首先当然是概述。

View File

@ -3,6 +3,7 @@
<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>
# 栈与队列总结篇 # 栈与队列总结篇
## 栈与队列的理论基础 ## 栈与队列的理论基础

View File

@ -196,7 +196,7 @@ impl Solution{
} }
``` ```
### Go ### Go
Go中slice的`append`操作和C++中vector的扩容机制基本相同。 Go中slice的`append`操作和C++中vector的扩容机制基本相同。
@ -213,4 +213,3 @@ Go中slice的`append`操作和C++中vector的扩容机制基本相同。
<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

@ -3,8 +3,11 @@
<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>
# 算法模板
## 二分查找法 ## 算法模板
### 二分查找法
```CPP ```CPP
class Solution { class Solution {
@ -29,7 +32,7 @@ public:
``` ```
## KMP ### KMP
```CPP ```CPP
void kmp(int* next, const string& s){ void kmp(int* next, const string& s){
@ -47,7 +50,7 @@ void kmp(int* next, const string& s){
} }
``` ```
## 二叉树 ### 二叉树
二叉树的定义: 二叉树的定义:
@ -60,7 +63,7 @@ struct TreeNode {
}; };
``` ```
### 深度优先遍历(递归) #### 深度优先遍历(递归)
前序遍历(中左右) 前序遍历(中左右)
```CPP ```CPP
@ -90,7 +93,7 @@ void traversal(TreeNode* cur, vector<int>& vec) {
} }
``` ```
### 深度优先遍历(迭代法) #### 深度优先遍历(迭代法)
相关题解:[0094.二叉树的中序遍历](https://github.com/youngyangyang04/leetcode/blob/master/problems/0094.二叉树的中序遍历.md) 相关题解:[0094.二叉树的中序遍历](https://github.com/youngyangyang04/leetcode/blob/master/problems/0094.二叉树的中序遍历.md)
@ -170,7 +173,7 @@ vector<int> postorderTraversal(TreeNode* root) {
return result; return result;
} }
``` ```
### 广度优先遍历(队列) #### 广度优先遍历(队列)
相关题解:[0102.二叉树的层序遍历](https://programmercarl.com/0102.二叉树的层序遍历.html) 相关题解:[0102.二叉树的层序遍历](https://programmercarl.com/0102.二叉树的层序遍历.html)
@ -208,7 +211,7 @@ vector<vector<int>> levelOrder(TreeNode* root) {
* [0111.二叉树的最小深度(迭代法)](https://programmercarl.com/0111.二叉树的最小深度.html) * [0111.二叉树的最小深度(迭代法)](https://programmercarl.com/0111.二叉树的最小深度.html)
* [0222.完全二叉树的节点个数(迭代法)](https://programmercarl.com/0222.完全二叉树的节点个数.html) * [0222.完全二叉树的节点个数(迭代法)](https://programmercarl.com/0222.完全二叉树的节点个数.html)
### 二叉树深度 #### 二叉树深度
```CPP ```CPP
int getDepth(TreeNode* node) { int getDepth(TreeNode* node) {
@ -217,7 +220,7 @@ int getDepth(TreeNode* node) {
} }
``` ```
### 二叉树节点数量 #### 二叉树节点数量
```CPP ```CPP
int countNodes(TreeNode* root) { int countNodes(TreeNode* root) {
@ -226,7 +229,7 @@ int countNodes(TreeNode* root) {
} }
``` ```
## 回溯算法 ### 回溯算法
```CPP ```CPP
void backtracking(参数) { void backtracking(参数) {
if (终止条件) { if (终止条件) {
@ -243,7 +246,7 @@ void backtracking(参数) {
``` ```
## 并查集 ### 并查集
```CPP ```CPP
int n = 1005; // 根据题意而定 int n = 1005; // 根据题意而定
@ -278,9 +281,9 @@ void backtracking(参数) {
持续补充ing 持续补充ing
## 其他语言版本 ## 其他语言版本
JavaScript ### JavaScript
## 二分查找法 #### 二分查找法
使用左闭右闭区间 使用左闭右闭区间
@ -322,7 +325,7 @@ var search = function (nums, target) {
}; };
``` ```
## KMP #### KMP
```javascript ```javascript
var kmp = function (next, s) { var kmp = function (next, s) {
@ -340,9 +343,9 @@ var kmp = function (next, s) {
} }
``` ```
## 二叉树 #### 二叉树
### 深度优先遍历(递归) ##### 深度优先遍历(递归)
二叉树节点定义: 二叉树节点定义:
@ -387,7 +390,7 @@ var postorder = function (root, list) {
} }
``` ```
### 深度优先遍历(迭代) ##### 深度优先遍历(迭代)
前序遍历(中左右): 前序遍历(中左右):
@ -447,7 +450,7 @@ var postorderTraversal = function (root) {
}; };
``` ```
### 广度优先遍历(队列) ##### 广度优先遍历(队列)
```javascript ```javascript
var levelOrder = function (root) { var levelOrder = function (root) {
@ -469,7 +472,7 @@ var levelOrder = function (root) {
}; };
``` ```
### 二叉树深度 ##### 二叉树深度
```javascript ```javascript
var getDepth = function (node) { var getDepth = function (node) {
@ -478,7 +481,7 @@ var getDepth = function (node) {
} }
``` ```
### 二叉树节点数量 ##### 二叉树节点数量
```javascript ```javascript
var countNodes = function (root) { var countNodes = function (root) {
@ -487,7 +490,7 @@ var countNodes = function (root) {
} }
``` ```
## 回溯算法 #### 回溯算法
```javascript ```javascript
function backtracking(参数) { function backtracking(参数) {
@ -505,7 +508,7 @@ function backtracking(参数) {
``` ```
## 并查集 #### 并查集
```javascript ```javascript
let n = 1005; // 根据题意而定 let n = 1005; // 根据题意而定
@ -536,9 +539,9 @@ function backtracking(参数) {
} }
``` ```
TypeScript ### TypeScript
## 二分查找法 #### 二分查找法
使用左闭右闭区间 使用左闭右闭区间
@ -580,7 +583,7 @@ var search = function (nums: number[], target: number): number {
}; };
``` ```
## KMP #### KMP
```typescript ```typescript
var kmp = function (next: number[], s: number): void { var kmp = function (next: number[], s: number): void {
@ -598,9 +601,9 @@ var kmp = function (next: number[], s: number): void {
} }
``` ```
## 二叉树 #### 二叉树
### 深度优先遍历(递归) ##### 深度优先遍历(递归)
二叉树节点定义: 二叉树节点定义:
@ -650,7 +653,7 @@ var postorder = function (root: TreeNode | null, list: number[]): void {
} }
``` ```
### 深度优先遍历(迭代) ##### 深度优先遍历(迭代)
前序遍历(中左右): 前序遍历(中左右):
@ -710,7 +713,7 @@ var postorderTraversal = function (root: TreeNode | null): number[] {
}; };
``` ```
### 广度优先遍历(队列) ##### 广度优先遍历(队列)
```typescript ```typescript
var levelOrder = function (root: TreeNode | null): number[] { var levelOrder = function (root: TreeNode | null): number[] {
@ -732,7 +735,7 @@ var levelOrder = function (root: TreeNode | null): number[] {
}; };
``` ```
### 二叉树深度 ##### 二叉树深度
```typescript ```typescript
var getDepth = function (node: TreNode | null): number { var getDepth = function (node: TreNode | null): number {
@ -741,7 +744,7 @@ var getDepth = function (node: TreNode | null): number {
} }
``` ```
### 二叉树节点数量 ##### 二叉树节点数量
```typescript ```typescript
var countNodes = function (root: TreeNode | null): number { var countNodes = function (root: TreeNode | null): number {
@ -750,7 +753,7 @@ var countNodes = function (root: TreeNode | null): number {
} }
``` ```
## 回溯算法 #### 回溯算法
```typescript ```typescript
function backtracking(参数) { function backtracking(参数) {
@ -768,7 +771,7 @@ function backtracking(参数) {
``` ```
## 并查集 #### 并查集
```typescript ```typescript
let n: number = 1005; // 根据题意而定 let n: number = 1005; // 根据题意而定
@ -801,9 +804,9 @@ function backtracking(参数) {
Java Java
### Python
Python #### 二分查找法
## 二分查找法
```python ```python
def binarysearch(nums, target): def binarysearch(nums, target):
low = 0 low = 0
@ -823,7 +826,7 @@ def binarysearch(nums, target):
return -1 return -1
``` ```
## KMP #### KMP
```python ```python
def kmp(self, a, s): def kmp(self, a, s):

View File

@ -3,8 +3,10 @@
<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背包理论基础滚动数组
## 算法公开课 ## 算法公开课
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[带你学透0-1背包问题滚动数组](https://www.bilibili.com/video/BV1BU4y177kY/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。 **[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html)[带你学透0-1背包问题滚动数组](https://www.bilibili.com/video/BV1BU4y177kY/),相信结合视频再看本篇题解,更有助于大家对本题的理解**。

View File

@ -3,6 +3,7 @@
<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>
# 链表总结篇 # 链表总结篇