diff --git a/README.md b/README.md index b1db51c903..92336a19fc 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ 按照先面的排列顺序,从数组开始刷起就可以了,顺序都安排好了,按顺序刷就好。 -在刷题攻略中,每个专题开始都有理论基础篇,并不像是教科书般的理论介绍,而是从实战中归纳需要的基础知识。每个专题结束都有总结篇,最这个专题的归纳总结。 +在刷题攻略中,每个专题开始都有理论基础篇,并不像是教科书般的理论介绍,而是从实战中归纳需要的基础知识。每个专题结束都有总结篇,是这个专题的归纳总结。 如果你是算法老手,这篇攻略也是复习的最佳资料,如果把每个系列对应的总结篇,快速过一遍,整个算法知识体系以及各种解法就重现脑海了。 @@ -69,13 +69,14 @@ ## 前序 -* [「代码随想录」学习社区](https://programmercarl.com/other/kstar.html) +* [做项目(多个C++、Java、Go、前端、测开项目)](https://programmercarl.com/other/kstar.html) * 编程语言 * [C++面试&C++学习指南知识点整理](https://github.com/youngyangyang04/TechCPP) * [编程语言基础课](https://kamacoder.com/courseshop.php) * [23种设计模式](https://github.com/youngyangyang04/kama-DesignPattern) + * [大厂算法笔试题](https://kamacoder.com/company.php) * 工具 * [一站式vim配置](https://github.com/youngyangyang04/PowerVim) @@ -180,7 +181,7 @@ 题目分类大纲如下: - + 1. [关于二叉树,你该了解这些!](./problems/二叉树理论基础.md) 2. [二叉树:二叉树的递归遍历](./problems/二叉树的递归遍历.md) @@ -221,7 +222,7 @@ 题目分类大纲如下: - + 1. [关于回溯算法,你该了解这些!](./problems/回溯算法理论基础.md) 2. [回溯算法:77.组合](./problems/0077.组合.md) @@ -251,7 +252,7 @@ 题目分类大纲如下: - + 1. [关于贪心算法,你该了解这些!](./problems/贪心算法理论基础.md) 2. [贪心算法:455.分发饼干](./problems/0455.分发饼干.md) @@ -282,7 +283,7 @@ 动态规划专题已经开始啦,来不及解释了,小伙伴们上车别掉队! - + 1. [关于动态规划,你该了解这些!](./problems/动态规划理论基础.md) 2. [动态规划:509.斐波那契数](./problems/0509.斐波那契数.md) 3. [动态规划:70.爬楼梯](./problems/0070.爬楼梯.md) @@ -296,7 +297,7 @@ 背包问题系列: - + 11. [动态规划:01背包理论基础(二维dp数组)](./problems/背包理论基础01背包-1.md) @@ -327,7 +328,7 @@ 股票系列: - + 32. [动态规划:121.买卖股票的最佳时机](./problems/0121.买卖股票的最佳时机.md) @@ -342,7 +343,7 @@ 子序列系列: - + 41. [动态规划:300.最长递增子序列](./problems/0300.最长上升子序列.md) @@ -385,9 +386,9 @@ 9. [图论:沉没孤岛](./problems/kamacoder/0102.沉没孤岛.md) 10. [图论:水流问题](./problems/kamacoder/0103.水流问题.md) 11. [图论:建造最大岛屿](./problems/kamacoder/0104.建造最大岛屿.md) -12. [图论:字符串接龙](./problems/kamacoder/0110.字符串接龙.md) -13. [图论:有向图的完全可达性](./problems/kamacoder/0105.有向图的完全可达性.md) -14. [图论:岛屿的周长](./problems/kamacoder/0106.岛屿的周长.md) +12. [图论:岛屿的周长](./problems/kamacoder/0106.岛屿的周长.md) +13. [图论:字符串接龙](./problems/kamacoder/0110.字符串接龙.md) +14. [图论:有向图的完全可达性](./problems/kamacoder/0105.有向图的完全可达性.md) 15. [图论:并查集理论基础](./problems/kamacoder/图论并查集理论基础.md) 16. [图论:寻找存在的路径](./problems/kamacoder/0107.寻找存在的路径.md) 17. [图论:冗余连接](./problems/kamacoder/0108.冗余连接.md) @@ -502,5 +503,5 @@ 添加微信记得备注,如果是已工作,备注:姓名-城市-岗位。如果学生,备注:姓名-学校-年级。**备注没有自我介绍不通过哦** -
+ diff --git "a/problems/0001.344円270円244円346円225円260円344円271円213円345円222円214円.md" "b/problems/0001.344円270円244円346円225円260円344円271円213円345円222円214円.md" old mode 100644 new mode 100755 index e982ae129b..be4455bda2 --- "a/problems/0001.344円270円244円346円225円260円344円271円213円345円222円214円.md" +++ "b/problems/0001.344円270円244円346円225円260円344円271円213円345円222円214円.md" @@ -1,8 +1,6 @@ -- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 1. 两数之和 @@ -85,10 +83,10 @@ map目的用来存放我们访问过的元素,因为遍历数组的时候, 过程如下: - + - + C++代码: @@ -287,17 +285,16 @@ func twoSum(nums []int, target int) []int { ``` ```go -// 使用map方式解题,降低时间复杂度 func twoSum(nums []int, target int) []int { m := make(map[int]int) - for index, val := range nums { - if preIndex, ok := m[target-val]; ok { - return []int{preIndex, index} - } else { - m[val] = index + for i, num := range nums { + complement := target - num + if index, found := m[complement]; found { + return []int{index, i} } + m[num] = i } - return []int{} + return nil // 返回空数组 nil 代替空切片 } ``` @@ -557,7 +554,3 @@ int* twoSum(int* nums, int numsSize, int target, int* returnSize){ } ``` -- - - diff --git "a/problems/0005.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円344円270円262円.md" "b/problems/0005.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円344円270円262円.md" old mode 100644 new mode 100755 index b3d3b93896..05dd610a72 --- "a/problems/0005.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円344円270円262円.md" +++ "b/problems/0005.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円344円270円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -108,7 +106,7 @@ dp[i][j]可以初始化为true么? 当然不行,怎能刚开始就全都匹 dp[i + 1][j - 1] 在 dp[i][j]的左下角,如图: - + 如果这矩阵是从上到下,从左到右遍历,那么会用到没有计算过的dp[i + 1][j - 1],也就是根据不确定是不是回文的区间[i+1,j-1],来判断了[i,j]是不是回文,那结果一定是不对的。 @@ -142,7 +140,7 @@ for (int i = s.size() - 1; i>= 0; i--) { // 注意遍历顺序 举例,输入:"aaa",dp[i][j]状态如下: - + **注意因为dp[i][j]的定义,所以j一定是大于等于i的,那么在填充dp[i][j]的时候一定是只填充右上半部分**。 @@ -731,8 +729,4 @@ public class Solution { ``` -- - - diff --git "a/problems/0015.344円270円211円346円225円260円344円271円213円345円222円214円.md" "b/problems/0015.344円270円211円346円225円260円344円271円213円345円222円214円.md" old mode 100644 new mode 100755 index 1685db7452..e2cb3f4612 --- "a/problems/0015.344円270円211円346円225円260円344円271円213円345円222円214円.md" +++ "b/problems/0015.344円270円211円346円225円260円344円271円213円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -102,7 +100,7 @@ public: 动画效果如下: - + 拿这个nums数组来举例,首先将数组排序,然后有一层for循环,i从下标0的地方开始,同时定一个下标left 定义在i+1的位置上,定义下标right 在数组结尾的位置上。 @@ -980,7 +978,3 @@ object Solution { } ``` -- - - diff --git "a/problems/0017.347円224円265円350円257円235円345円217円267円347円240円201円347円232円204円345円255円227円346円257円215円347円273円204円345円220円210円.md" "b/problems/0017.347円224円265円350円257円235円345円217円267円347円240円201円347円232円204円345円255円227円346円257円215円347円273円204円345円220円210円.md" old mode 100644 new mode 100755 index 9a320ca0e6..6dcf9ee690 --- "a/problems/0017.347円224円265円350円257円235円345円217円267円347円240円201円347円232円204円345円255円227円346円257円215円347円273円204円345円220円210円.md" +++ "b/problems/0017.347円224円265円350円257円235円345円217円267円347円240円201円347円232円204円345円255円227円346円257円215円347円273円204円345円220円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 17.电话号码的字母组合 @@ -13,7 +11,7 @@ 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 - + 示例: * 输入:"23" @@ -66,7 +64,7 @@ const string letterMap[10] = { 例如:输入:"23",抽象为树形结构,如图所示: - + 图中可以看出遍历的深度,就是输入"23"的长度,而叶子节点就是我们要收集的结果,输出["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]。 @@ -766,7 +764,3 @@ public class Solution ``` -- - - diff --git "a/problems/0018.345円233円233円346円225円260円344円271円213円345円222円214円.md" "b/problems/0018.345円233円233円346円225円260円344円271円213円345円222円214円.md" old mode 100644 new mode 100755 index f3188b0f13..bf7d3bd4ee --- "a/problems/0018.345円233円233円346円225円260円344円271円213円345円222円214円.md" +++ "b/problems/0018.345円233円233円346円225円260円344円271円213円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 一样的道理,能解决四数之和 @@ -798,8 +796,4 @@ def four_sum(nums, target) end ``` -- - - diff --git "a/problems/0019.345円210円240円351円231円244円351円223円276円350円241円250円347円232円204円345円200円222円346円225円260円347円254円254円N344円270円252円350円212円202円347円202円271円.md" "b/problems/0019.345円210円240円351円231円244円351円223円276円350円241円250円347円232円204円345円200円222円346円225円260円347円254円254円N344円270円252円350円212円202円347円202円271円.md" old mode 100644 new mode 100755 index 16312d0fc4..08f602c1c1 --- "a/problems/0019.345円210円240円351円231円244円351円223円276円350円241円250円347円232円204円345円200円222円346円225円260円347円254円254円N344円270円252円350円212円202円347円202円271円.md" +++ "b/problems/0019.345円210円240円351円231円244円351円223円276円350円241円250円347円232円204円345円200円222円346円225円260円347円254円254円N344円270円252円350円212円202円347円202円271円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -18,7 +16,7 @@ 示例 1: - + 输入:head = [1,2,3,4,5], n = 2 输出:[1,2,3,5] @@ -51,16 +49,16 @@ * 定义fast指针和slow指针,初始值为虚拟头结点,如图: - + * fast首先走n + 1步 ,为什么是n+1呢,因为只有这样同时移动的时候slow才能指向删除节点的上一个节点(方便做删除操作),如图: - + * fast和slow同时移动,直到fast指向末尾,如题: - + //图片中有错别词:应该将"只到"改为"直到" * 删除slow指向的下一个节点,如图: - + 此时不难写出如下C++代码: @@ -479,7 +477,3 @@ public class Solution { } } ``` -- - - diff --git "a/problems/0020.346円234円211円346円225円210円347円232円204円346円213円254円345円217円267円.md" "b/problems/0020.346円234円211円346円225円210円347円232円204円346円213円254円345円217円267円.md" old mode 100644 new mode 100755 index 2475138ebb..09cf997839 --- "a/problems/0020.346円234円211円346円225円210円347円232円204円346円213円254円345円217円267円.md" +++ "b/problems/0020.346円234円211円346円225円210円347円232円204円346円213円254円345円217円267円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -83,13 +81,13 @@ cd a/b/c/../../ 1. 第一种情况,字符串里左方向的括号多余了 ,所以不匹配。 - + 2. 第二种情况,括号没有多余,但是 括号的类型没有匹配上。 - + 3. 第三种情况,字符串里右方向的括号多余了,所以不匹配。 - + @@ -97,7 +95,7 @@ cd a/b/c/../../ 动画如下: - + 第一种情况:已经遍历完了字符串,但是栈不为空,说明有相应的左括号没有右括号来匹配,所以return false @@ -574,8 +572,4 @@ impl Solution { } ``` -- - - diff --git "a/problems/0024.344円270円244円344円270円244円344円272円244円346円215円242円351円223円276円350円241円250円344円270円255円347円232円204円350円212円202円347円202円271円.md" "b/problems/0024.344円270円244円344円270円244円344円272円244円346円215円242円351円223円276円350円241円250円344円270円255円347円232円204円350円212円202円347円202円271円.md" old mode 100644 new mode 100755 index 305bb7ccba..14d2538f45 --- "a/problems/0024.344円270円244円344円270円244円344円272円244円346円215円242円351円223円276円350円241円250円344円270円255円347円232円204円350円212円202円347円202円271円.md" +++ "b/problems/0024.344円270円244円344円270円244円344円272円244円346円215円242円351円223円276円350円241円250円344円270円255円347円232円204円350円212円202円347円202円271円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 24. 两两交换链表中的节点 @@ -14,7 +12,7 @@ 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 - + ## 算法公开课 @@ -33,16 +31,16 @@ 初始时,cur指向虚拟头结点,然后进行如下三步: - + 操作之后,链表如下: - + 看这个可能就更直观一些了: - + 对应的C++代码实现如下: (注释中详细和如上图中的三步做对应) @@ -83,7 +81,7 @@ public: 心想应该没有更好的方法了吧,也就 $O(n)$ 的时间复杂度,重复提交几次,这样了: - + 力扣上的统计如果两份代码是 100ms 和 300ms的耗时,其实是需要注意的。 @@ -527,7 +525,3 @@ public ListNode SwapPairs(ListNode head) } ``` -- - - diff --git "a/problems/0027.347円247円273円351円231円244円345円205円203円347円264円240円.md" "b/problems/0027.347円247円273円351円231円244円345円205円203円347円264円240円.md" old mode 100644 new mode 100755 index 10817ba6b7..47e05eec6a --- "a/problems/0027.347円247円273円351円231円244円345円205円203円347円264円240円.md" +++ "b/problems/0027.347円247円273円351円231円244円345円205円203円347円264円240円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 27. 移除元素 @@ -45,7 +43,7 @@ 删除过程如下: - + 很明显暴力解法的时间复杂度是O(n^2),这道题目暴力解法在leetcode上是可以过的。 @@ -89,7 +87,7 @@ public: 删除过程如下: - + 很多同学不了解 @@ -519,7 +517,3 @@ int removeElement(List- - - diff --git "a/problems/0028.345円256円236円347円216円260円strStr.md" "b/problems/0028.345円256円236円347円216円260円strStr.md" old mode 100644 new mode 100755 index 63a08d960d..ef8a6c58e6 --- "a/problems/0028.345円256円236円347円216円260円strStr.md" +++ "b/problems/0028.345円256円236円347円216円260円strStr.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 在一个串中查找是否出现过另一个串,这是KMP的看家本领。 @@ -108,7 +106,7 @@ next数组就是一个前缀表(prefix table)。 如动画所示: - + 动画里,我特意把 子串`aa` 标记上了,这是有原因的,大家先注意一下,后面还会说到。 @@ -149,11 +147,11 @@ next数组就是一个前缀表(prefix table)。 这就是前缀表,那为啥就能告诉我们 上次匹配的位置,并跳过去呢? 回顾一下,刚刚匹配的过程在下标5的地方遇到不匹配,模式串是指向f,如图: - + 然后就找到了下标2,指向b,继续匹配:如图: - + 以下这句话,对于理解为什么使用前缀表可以告诉我们匹配失败之后跳到哪里重新匹配 非常重要! @@ -169,15 +167,15 @@ next数组就是一个前缀表(prefix table)。 如图: - + 长度为前1个字符的子串`a`,最长相同前后缀的长度为0。(注意字符串的**前缀是指不包含最后一个字符的所有以第一个字符开头的连续子串**;**后缀是指不包含第一个字符的所有以最后一个字符结尾的连续子串**。) - + 长度为前2个字符的子串`aa`,最长相同前后缀的长度为1。 - + 长度为前3个字符的子串`aab`,最长相同前后缀的长度为0。 @@ -187,13 +185,13 @@ next数组就是一个前缀表(prefix table)。 长度为前6个字符的子串`aabaaf`,最长相同前后缀的长度为0。 那么把求得的最长相同前后缀的长度就是对应前缀表的元素,如图: - + 可以看出模式串与前缀表对应位置的数字表示的就是:**下标i之前(包括i)的字符串中,有多大长度的相同前缀后缀。** 再来看一下如何利用 前缀表找到 当字符不匹配的时候应该指针应该移动的位置。如动画所示: - + 找到的不匹配的位置, 那么此时我们要看它的前一个字符的前缀表的数值是多少。 @@ -227,7 +225,7 @@ next数组就可以是前缀表,但是很多实现都是把前缀表统一减 匹配过程动画如下: - + ### 时间复杂度分析 @@ -334,7 +332,7 @@ void getNext(int* next, const string& s){ 代码构造next数组的逻辑流程动画如下: - + 得到了next数组之后,就要用这个来做匹配了。 @@ -1520,7 +1518,3 @@ int strStr(char* haystack, char* needle) { } ``` -- - - diff --git "a/problems/0031.344円270円213円344円270円200円344円270円252円346円216円222円345円210円227円.md" "b/problems/0031.344円270円213円344円270円200円344円270円252円346円216円222円345円210円227円.md" old mode 100644 new mode 100755 index 48af8d0da1..4bbf20fbb8 --- "a/problems/0031.344円270円213円344円270円200円344円270円252円346円216円222円345円210円227円.md" +++ "b/problems/0031.344円270円213円344円270円200円344円270円252円346円216円222円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -69,7 +67,7 @@ 以求1243为例,流程如图: - + 对应的C++代码如下: @@ -269,7 +267,3 @@ var nextPermutation = function(nums) { -- - - diff --git "a/problems/0034.345円234円250円346円216円222円345円272円217円346円225円260円347円273円204円344円270円255円346円237円245円346円211円276円345円205円203円347円264円240円347円232円204円347円254円254円344円270円200円344円270円252円345円222円214円346円234円200円345円220円216円344円270円200円344円270円252円344円275円215円347円275円256円.md" "b/problems/0034.345円234円250円346円216円222円345円272円217円346円225円260円347円273円204円344円270円255円346円237円245円346円211円276円345円205円203円347円264円240円347円232円204円347円254円254円344円270円200円344円270円252円345円222円214円346円234円200円345円220円216円344円270円200円344円270円252円344円275円215円347円275円256円.md" old mode 100644 new mode 100755 index 16adcdf19c..37248e4819 --- "a/problems/0034.345円234円250円346円216円222円345円272円217円346円225円260円347円273円204円344円270円255円346円237円245円346円211円276円345円205円203円347円264円240円347円232円204円347円254円254円344円270円200円344円270円252円345円222円214円346円234円200円345円220円216円344円270円200円344円270円252円344円275円215円347円275円256円.md" +++ "b/problems/0034.345円234円250円346円216円222円345円272円217円346円225円260円347円273円204円344円270円255円346円237円245円346円211円276円345円205円203円347円264円240円347円232円204円347円254円254円344円270円200円344円270円252円345円222円214円346円234円200円345円220円216円344円270円200円344円270円252円344円275円215円347円275円256円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 34. 在排序数组中查找元素的第一个和最后一个位置 @@ -855,7 +853,3 @@ int* searchRange(int* nums, int numsSize, int target, int* returnSize){ ``` -- - - diff --git "a/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" "b/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" old mode 100644 new mode 100755 index b5be9a5f8b..b48910eef7 --- "a/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" +++ "b/problems/0035.346円220円234円347円264円242円346円217円222円345円205円245円344円275円215円347円275円256円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -43,7 +41,7 @@ 这道题目,要在数组中插入目标值,无非是这四种情况。 - + * 目标值在数组所有元素之前 * 目标值等于数组中某一个元素 @@ -84,14 +82,14 @@ public: 效率如下: - + ### 二分法 既然暴力解法的时间复杂度是O(n),就要尝试一下使用二分查找法。 - + 大家注意这道题目的前提是数组是有序数组,这也是使用二分查找的基础条件。 @@ -101,7 +99,7 @@ public: 大体讲解一下二分法的思路,这里来举一个例子,例如在这个数组中,使用二分法寻找元素为5的位置,并返回其下标。 - + 二分查找涉及的很多的边界条件,逻辑比较简单,就是写不好。 @@ -152,7 +150,7 @@ public: * 空间复杂度:O(1) 效率如下: - + ### 二分法第二种写法 @@ -549,7 +547,3 @@ int searchInsert(int* nums, int numsSize, int target){ ``` -- - - diff --git "a/problems/0037.350円247円243円346円225円260円347円213円254円.md" "b/problems/0037.350円247円243円346円225円260円347円213円254円.md" old mode 100644 new mode 100755 index 5f3f881cf1..204f0cc092 --- "a/problems/0037.350円247円243円346円225円260円347円213円254円.md" +++ "b/problems/0037.350円247円243円346円225円260円347円213円254円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -20,11 +18,11 @@ 数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。 空白格用 '.' 表示。 - + 一个数独。 - + 答案被标成红色。 @@ -54,7 +52,7 @@ 因为这个树形结构太大了,我抽取一部分,如图所示: - + ### 回溯三部曲 @@ -85,7 +83,7 @@ bool backtracking(vector- - - diff --git "a/problems/0039.347円273円204円345円220円210円346円200円273円345円222円214円.md" "b/problems/0039.347円273円204円345円220円210円346円200円273円345円222円214円.md" old mode 100644 new mode 100755 index 92c68562da..d8dac0b45b --- "a/problems/0039.347円273円204円345円220円210円346円200円273円345円222円214円.md" +++ "b/problems/0039.347円273円204円345円220円210円346円200円273円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -52,7 +50,7 @@ candidates 中的数字可以无限制重复被选取。 本题搜索的过程抽象成树形结构如下: - + 注意图中叶子节点的返回条件,因为本题没有组合数量要求,仅仅是总和的限制,所以递归没有层数的限制,只要选取的元素总和超过target,就返回! 而在[77.组合](https://programmercarl.com/0077.组合.html)和[216.组合总和III](https://programmercarl.com/0216.组合总和III.html) 中都可以知道要递归K层,因为要取k个元素的组合。 @@ -87,7 +85,7 @@ void backtracking(vector- - - diff --git "a/problems/0040.347円273円204円345円220円210円346円200円273円345円222円214円II.md" "b/problems/0040.347円273円204円345円220円210円346円200円273円345円222円214円II.md" old mode 100644 new mode 100755 index 22cf726d8c..0d3972662f --- "a/problems/0040.347円273円204円345円220円210円346円200円273円345円222円214円II.md" +++ "b/problems/0040.347円273円204円345円220円210円346円200円273円345円222円214円II.md" @@ -1,12 +1,8 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) -> 这篇可以说是全网把组合问题如何去重,讲的最清晰的了! - # 40.组合总和II [力扣题目链接](https://leetcode.cn/problems/combination-sum-ii/) @@ -80,7 +76,7 @@ candidates 中的每个数字在每个组合中只能使用一次。 选择过程树形结构如图所示: - + 可以看到图中,每个节点相对于 [39.组合总和](https://mp.weixin.qq.com/s/FLg8G6EjVcxBjwCbzpACPw)我多加了used数组,这个used数组下面会重点介绍。 @@ -130,7 +126,7 @@ if (sum == target) { 这块比较抽象,如图: - + 我在图中将used的变化用橘黄色标注上,可以看出在candidates[i] == candidates[i - 1]相同的情况下: @@ -141,7 +137,7 @@ if (sum == target) { 而 used[i - 1] == true,说明是进入下一层递归,去下一个数,所以是树枝上,如图所示: - + **这块去重的逻辑很抽象,网上搜的题解基本没有能讲清楚的,如果大家之前思考过这个问题或者刷过这道题目,看到这里一定会感觉通透了很多!** @@ -807,7 +803,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0042.346円216円245円351円233円250円346円260円264円.md" "b/problems/0042.346円216円245円351円233円250円346円260円264円.md" old mode 100644 new mode 100755 index 0484f830f6..62fbe270b7 --- "a/problems/0042.346円216円245円351円233円250円346円260円264円.md" +++ "b/problems/0042.346円216円245円351円233円250円346円260円264円.md" @@ -1,13 +1,10 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) -> 这个图就是大厂面试经典题目,接雨水! 最常青藤的一道题,面试官百出不厌! # 42. 接雨水 @@ -17,8 +14,7 @@ 示例 1: - - + * 输入:height = [0,1,0,2,1,0,1,3,2,1,2,1] * 输出:6 * 解释:上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 @@ -50,10 +46,10 @@ 首先要明确,要按照行来计算,还是按照列来计算。 按照行来计算如图: - + 按照列来计算如图: - + 一些同学在实现的时候,很容易一会按照行来计算一会按照列来计算,这样就会越写越乱。 @@ -65,7 +61,7 @@ 这句话可以有点绕,来举一个理解,例如求列4的雨水高度,如图: - + 列4 左侧最高的柱子是列3,高度为2(以下用lHeight表示)。 @@ -204,7 +200,7 @@ public: 1. 首先单调栈是按照行方向来计算雨水,如图: - + 知道这一点,后面的就可以理解了。 @@ -218,7 +214,7 @@ public: 如图: - + 关于单调栈的顺序给大家一个总结: [739. 每日温度](https://programmercarl.com/0739.每日温度.html) 中求一个元素右边第一个更大元素,单调栈就是递增的,[84.柱状图中最大的矩形](https://programmercarl.com/0084.柱状图中最大的矩形.html)求一个元素右边第一个更小元素,单调栈就是递减的。 @@ -232,7 +228,7 @@ public: 如图所示: - + 4. 栈里要保存什么数值 @@ -287,7 +283,7 @@ if (height[i] == height[st.top()]) { // 例如 5 5 1 7 这种情况 如果当前遍历的元素(柱子)高度大于栈顶元素的高度,此时就出现凹槽了,如图所示: - + 取栈顶元素,将栈顶元素弹出,这个就是凹槽的底部,也就是中间位置,下标记为mid,对应的高度为height[mid](就是图中的高度1)。 @@ -1095,7 +1091,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0045.350円267円263円350円267円203円346円270円270円346円210円217円II.md" "b/problems/0045.350円267円263円350円267円203円346円270円270円346円210円217円II.md" old mode 100644 new mode 100755 index 8919d39367..c20cdc65e6 --- "a/problems/0045.350円267円263円350円267円203円346円270円270円346円210円217円II.md" +++ "b/problems/0045.350円267円263円350円267円203円346円270円270円346円210円217円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 相对于[贪心算法:跳跃游戏](https://mp.weixin.qq.com/s/606_N9j8ACKCODoCbV1lSA)难了不少,做好心理准备! @@ -49,7 +47,7 @@ 如图: - + **图中覆盖范围的意义在于,只要红色的区域,最多两步一定可以到!(不用管具体怎么跳,反正一定可以跳到)** @@ -101,11 +99,11 @@ public: 因为当移动下标指向 nums.size - 2 时: - 如果移动下标等于当前覆盖最大距离下标, 需要再走一步(即 ans++),因为最后一步一定是可以到的终点。(题目假设总是可以到达数组的最后一个位置),如图: -  +  - 如果移动下标不等于当前覆盖最大距离下标,说明当前覆盖最远距离就可以直接达到终点了,不需要再走一步。如图: - + 代码如下: @@ -542,7 +540,3 @@ public class Solution ``` -- - - diff --git "a/problems/0046.345円205円250円346円216円222円345円210円227円.md" "b/problems/0046.345円205円250円346円216円222円345円210円227円.md" old mode 100644 new mode 100755 index ca465efd6f..356f51b5a8 --- "a/problems/0046.345円205円250円346円216円222円345円210円227円.md" +++ "b/problems/0046.345円205円250円346円216円222円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 46.全排列 @@ -43,7 +41,7 @@ 我以[1,2,3]为例,抽象成树形结构如下: - + ### 回溯三部曲 @@ -55,7 +53,7 @@ 但排列问题需要一个used数组,标记已经选择的元素,如图橘黄色部分所示: - + 代码如下: @@ -67,7 +65,7 @@ void backtracking (vector- - - diff --git "a/problems/0047.345円205円250円346円216円222円345円210円227円II.md" "b/problems/0047.345円205円250円346円216円222円345円210円227円II.md" old mode 100644 new mode 100755 index 08e3c616a2..5330997a66 --- "a/problems/0047.345円205円250円346円216円222円345円210円227円II.md" +++ "b/problems/0047.345円205円250円346円216円222円345円210円227円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -50,7 +48,7 @@ 我以示例中的 [1,1,2]为例 (为了方便举例,已经排序)抽象为一棵树,去重过程如图: - + 图中我们对同一树层,前一位(也就是nums[i-1])如果使用过,那么就进行去重。 @@ -132,11 +130,11 @@ if (i> 0 && nums[i] == nums[i - 1] && used[i - 1] == true) { 树层上去重(used[i - 1] == false),的树形结构如下: - + 树枝上去重(used[i - 1] == true)的树型结构如下: - + 大家应该很清晰的看到,树层上对前一位去重非常彻底,效率很高,树枝上对前一位去重虽然最后可以得到答案,但是做了很多无用搜索。 @@ -555,7 +553,3 @@ public class Solution ``` -- - - diff --git "a/problems/0051.N347円232円207円345円220円216円.md" "b/problems/0051.N347円232円207円345円220円216円.md" old mode 100644 new mode 100755 index 38fc07e790..d06d7798e8 --- "a/problems/0051.N347円232円207円345円220円216円.md" +++ "b/problems/0051.N347円232円207円345円220円216円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 51. N皇后 @@ -17,7 +15,7 @@ n 皇后问题 研究的是如何将 n 个皇后放置在 n×ばつn 的棋盘上, 示例 1: - + * 输入:n = 4 * 输出:[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]] @@ -47,7 +45,7 @@ n 皇后问题 研究的是如何将 n 个皇后放置在 n×ばつn 的棋盘上, 下面我用一个 3 * 3 的棋盘,将搜索过程抽象为一棵树,如图: - + 从图中,可以看出,二维矩阵中矩阵的高就是这棵树的高度,矩阵的宽就是树形结构中每一个节点的宽度。 @@ -87,7 +85,7 @@ void backtracking(int n, int row, vector- - - diff --git "a/problems/0052.N347円232円207円345円220円216円II.md" "b/problems/0052.N347円232円207円345円220円216円II.md" old mode 100644 new mode 100755 index 271484a4ee..6c6650ad00 --- "a/problems/0052.N347円232円207円345円220円216円II.md" +++ "b/problems/0052.N347円232円207円345円220円216円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -15,7 +13,7 @@ n 皇后问题研究的是如何将 n 个皇后放置在 n×ばつn 的棋盘上,并 上图为 8 皇后问题的一种解法。 - + 给定一个整数 n,返回 n 皇后不同的解决方案的数量。 @@ -307,7 +305,3 @@ class Solution { } ``` -- - - diff --git "a/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円.md" "b/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円.md" old mode 100644 new mode 100755 index 705a00d7a8..84bb5f6663 --- "a/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円.md" +++ "b/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 53. 最大子序和 @@ -78,7 +76,7 @@ if (count> result) result = count; 如动画所示: - + 红色的起始位置就是贪心每次取 count 为正数的时候,开始一个区间的统计。 @@ -492,7 +490,3 @@ public class Solution ``` -- - - diff --git "a/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" "b/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" old mode 100644 new mode 100755 index 38a3a11818..ba44a36104 --- "a/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" +++ "b/problems/0053.346円234円200円345円244円247円345円255円220円345円272円217円345円222円214円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 53. 最大子序和 @@ -56,7 +54,7 @@ dp[0]应该是多少呢? 5. 举例推导dp数组 以示例一为例,输入:nums = [-2,1,-3,4,-1,2,1,-5,4],对应的dp状态如下: - + **注意最后的结果可不是dp[nums.size() - 1]!** ,而是dp[6]。 @@ -244,7 +242,3 @@ function maxSubArray(nums: number[]): number { -- - - diff --git "a/problems/0054.350円236円272円346円227円213円347円237円251円351円230円265円.md" "b/problems/0054.350円236円272円346円227円213円347円237円251円351円230円265円.md" old mode 100644 new mode 100755 index 3b7afb9099..8b700c1fe8 --- "a/problems/0054.350円236円272円346円227円213円347円237円251円351円230円265円.md" +++ "b/problems/0054.350円236円272円346円227円213円347円237円251円351円230円265円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -38,7 +36,7 @@ 由外向内一圈一圈这么画下去,如下所示: - + 这里每一种颜色,代表一条边,我们遍历的长度,可以看出每一个拐角处的处理规则,拐角处让给新的一条边来继续画。 @@ -485,7 +483,3 @@ func min(x, y int) int { ``` -- - - diff --git "a/problems/0055.350円267円263円350円267円203円346円270円270円346円210円217円.md" "b/problems/0055.350円267円263円350円267円203円346円270円270円346円210円217円.md" old mode 100644 new mode 100755 index 896dc998d1..513fc2e340 --- "a/problems/0055.350円267円263円350円267円203円346円270円270円346円210円217円.md" +++ "b/problems/0055.350円267円263円350円267円203円346円270円270円346円210円217円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 55. 跳跃游戏 @@ -50,7 +48,7 @@ 如图: - + i 每次移动只能在 cover 的范围内移动,每移动一个元素,cover 得到该元素数值(新的覆盖范围)的补充,让 i 继续移动下去。 @@ -293,7 +291,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0056.345円220円210円345円271円266円345円214円272円351円227円264円.md" "b/problems/0056.345円220円210円345円271円266円345円214円272円351円227円264円.md" old mode 100644 new mode 100755 index 538be69336..24a97f6c5a --- "a/problems/0056.345円220円210円345円271円266円345円214円272円351円227円264円.md" +++ "b/problems/0056.345円220円210円345円271円266円345円214円272円351円227円264円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 56. 合并区间 @@ -40,7 +38,7 @@ 这么说有点抽象,看图:(**注意图中区间都是按照左边界排序之后了**) - + 知道如何判断重复之后,剩下的就是合并了,如何去模拟合并区间呢? @@ -405,7 +403,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md" "b/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md" old mode 100644 new mode 100755 index 94966126b9..927df1c6c1 --- "a/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md" +++ "b/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -56,7 +54,7 @@ 那么我按照左闭右开的原则,来画一圈,大家看一下: - + 这里每一种颜色,代表一条边,我们遍历的长度,可以看出每一个拐角处的处理规则,拐角处让给新的一条边来继续画。 @@ -829,7 +827,3 @@ def generate_matrix(n) end ``` -- - - diff --git "a/problems/0062.344円270円215円345円220円214円350円267円257円345円276円204円.md" "b/problems/0062.344円270円215円345円220円214円350円267円257円345円276円204円.md" old mode 100644 new mode 100755 index 7025135ade..ac60767dce --- "a/problems/0062.344円270円215円345円220円214円350円267円257円345円276円204円.md" +++ "b/problems/0062.344円270円215円345円220円214円350円267円257円345円276円204円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -18,7 +16,7 @@ 示例 1: - + * 输入:m = 3, n = 7 * 输出:28 @@ -64,7 +62,7 @@ 如图举例: - + 此时问题就可以转化为求二叉树叶子节点的个数,代码如下: @@ -133,7 +131,7 @@ for (int j = 0; j < n; j++) dp[0][j] = 1; 如图所示: - + 以上动规五部曲分析完毕,C++代码如下: @@ -182,7 +180,7 @@ public: 在这个图中,可以看出一共m,n的话,无论怎么走,走到终点都需要 m + n - 2 步。 - + 在这m + n - 2 步中,一定有 m - 1 步是要向下走的,不用管什么时候向下走。 @@ -192,7 +190,7 @@ public: 那么答案,如图所示: - + **求组合的时候,要防止两个int相乘溢出!** 所以不能把算式的分子都算出来,分母都算出来再做除法。 @@ -616,7 +614,3 @@ public class Solution -- - - diff --git "a/problems/0063.344円270円215円345円220円214円350円267円257円345円276円204円II.md" "b/problems/0063.344円270円215円345円220円214円350円267円257円345円276円204円II.md" old mode 100644 new mode 100755 index 13923abeca..f39afe8455 --- "a/problems/0063.344円270円215円345円220円214円350円267円257円345円276円204円II.md" +++ "b/problems/0063.344円270円215円345円220円214円350円267円257円345円276円204円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -16,13 +14,13 @@ 现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径? - + 网格中的障碍物和空位置分别用 1 和 0 来表示。 示例 1: - + * 输入:obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]] * 输出:2 @@ -34,7 +32,7 @@ 示例 2: - + * 输入:obstacleGrid = [[0,1],[0,0]] * 输出:1 @@ -95,7 +93,7 @@ for (int j = 0; j < n; j++) dp[0][j] = 1; 如图: - + 下标(0, j)的初始化情况同理。 @@ -129,11 +127,11 @@ for (int i = 1; i < m; i++) { 拿示例1来举例如题: - + 对应的dp table 如图: - + 如果这个图看不懂,建议再理解一下递归公式,然后照着文章中说的遍历顺序,自己推导一下! @@ -781,7 +779,3 @@ public class Solution ``` -- - - diff --git "a/problems/0070.347円210円254円346円245円274円346円242円257円.md" "b/problems/0070.347円210円254円346円245円274円346円242円257円.md" old mode 100644 new mode 100755 index 6a13a21cdb..316fbd4f39 --- "a/problems/0070.347円210円254円346円245円274円346円242円257円.md" +++ "b/problems/0070.347円210円254円346円245円274円346円242円257円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 70. 爬楼梯 @@ -103,7 +101,7 @@ dp[i]: 爬到第i层楼梯,有dp[i]种方法 举例当n为5的时候,dp table(dp数组)应该是这样的 - + 如果代码出问题了,就把dp table 打印出来,看看究竟是不是和自己推导的一样。 @@ -520,8 +518,4 @@ impl Solution { ``` -- - - diff --git "a/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" "b/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" old mode 100644 new mode 100755 index c51a590baf..a5435ddd71 --- "a/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" +++ "b/problems/0070.347円210円254円346円245円274円346円242円257円345円256円214円345円205円250円350円203円214円345円214円205円347円211円210円346円234円254円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 70. 爬楼梯(进阶版) @@ -252,7 +250,3 @@ var climbStairs = function (n: number): number { ### Rust: -- - - diff --git "a/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" "b/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" old mode 100644 new mode 100755 index 0da3bf5093..c4bcbb4338 --- "a/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" +++ "b/problems/0072.347円274円226円350円276円221円350円267円235円347円246円273円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 72. 编辑距离 @@ -172,7 +170,7 @@ for (int j = 0; j <= word2.size(); j++) dp[0][j] = j; 可以看出dp[i][j]是依赖左方,上方和左上方元素的,如图: - + 所以在dp矩阵中一定是从左到右从上到下去遍历。 @@ -196,7 +194,7 @@ for (int i = 1; i <= word1.size(); i++) { 以示例1为例,输入:`word1 = "horse", word2 = "ros"`为例,dp矩阵状态图如下: - + 以上动规五部分析完毕,C++代码如下: @@ -462,7 +460,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0077.347円273円204円345円220円210円.md" "b/problems/0077.347円273円204円345円220円210円.md" old mode 100644 new mode 100755 index c4be5a3804..4c9e97fd47 --- "a/problems/0077.347円273円204円345円220円210円.md" +++ "b/problems/0077.347円273円204円345円220円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 第77题. 组合 @@ -84,7 +82,7 @@ for (int i = 1; i <= n; i++) { 那么我把组合问题抽象为如下树形结构: - + 可以看出这棵树,一开始集合是 1,2,3,4, 从左向右取数,取过的数,不再重复取。 @@ -128,7 +126,7 @@ vector- - - diff --git "a/problems/0077.347円273円204円345円220円210円344円274円230円345円214円226円.md" "b/problems/0077.347円273円204円345円220円210円344円274円230円345円214円226円.md" old mode 100644 new mode 100755 index 0fa568afe9..8ddc4058cc --- "a/problems/0077.347円273円204円345円220円210円344円274円230円345円214円226円.md" +++ "b/problems/0077.347円273円204円345円220円210円344円274円230円345円214円226円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -69,7 +67,7 @@ for (int i = startIndex; i <= n; i++) { 这么说有点抽象,如图所示: - + 图中每一个节点(图中为矩形),就代表本层的一个for循环,那么每一层的for循环从第二个数开始遍历的话,都没有意义,都是无效遍历。 @@ -412,7 +410,3 @@ object Solution { ``` -- - - diff --git "a/problems/0078.345円255円220円351円233円206円.md" "b/problems/0078.345円255円220円351円233円206円.md" old mode 100644 new mode 100755 index 0c368b41ed..844b8dc2ca --- "a/problems/0078.345円255円220円351円233円206円.md" +++ "b/problems/0078.345円255円220円351円233円206円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 78.子集 @@ -48,7 +46,7 @@ 以示例中nums = [1,2,3]为例把求子集抽象为树型结构,如下: - + 从图中红线部分,可以看出**遍历这个树的时候,把所有节点都记录下来,就是要求的子集集合**。 @@ -72,7 +70,7 @@ void backtracking(vector- - - diff --git "a/problems/0084.346円237円261円347円212円266円345円233円276円344円270円255円346円234円200円345円244円247円347円232円204円347円237円251円345円275円242円.md" "b/problems/0084.346円237円261円347円212円266円345円233円276円344円270円255円346円234円200円345円244円247円347円232円204円347円237円251円345円275円242円.md" old mode 100644 new mode 100755 index 5c6f407321..99fb1678e6 --- "a/problems/0084.346円237円261円347円212円266円345円233円276円344円270円255円346円234円200円345円244円247円347円232円204円347円237円251円345円275円242円.md" +++ "b/problems/0084.346円237円261円347円212円266円345円233円276円344円270円255円346円234円200円345円244円247円347円232円204円347円237円251円345円275円242円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 84.柱状图中最大的矩形 @@ -13,9 +11,9 @@ 求在该柱状图中,能够勾勒出来的矩形的最大面积。 - + - + * 1 <= heights.length <=10^5 * 0 <= heights[i] <= 10^4 @@ -116,7 +114,7 @@ public: 我来举一个例子,如图: - + 只有栈里从大到小的顺序,才能保证栈顶元素找到左右两边第一个小于栈顶元素的柱子。 @@ -181,7 +179,7 @@ public: 如果数组本身就是升序的,例如[2,4,6,8],那么入栈之后 都是单调递减,一直都没有走 情况三 计算结果的哪一步,所以最后输出的就是0了。 如图: - + 那么结尾加一个0,就会让栈里的所有元素,走到情况三的逻辑。 @@ -196,7 +194,7 @@ public: 之后又将6 加入栈(此时8已经弹出了),然后 就是 4 与 栈口元素 6 进行比较,周而复始,那么计算的最后结果result就是0。 如图所示: - + 所以我们需要在 height数组前后各加一个元素0。 @@ -863,7 +861,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0090.345円255円220円351円233円206円II.md" "b/problems/0090.345円255円220円351円233円206円II.md" old mode 100644 new mode 100755 index 811d3cc005..2e8945c90f --- "a/problems/0090.345円255円220円351円233円206円II.md" +++ "b/problems/0090.345円255円220円351円233円206円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 90.子集II @@ -41,7 +39,7 @@ 用示例中的[1, 2, 2] 来举例,如图所示: (**注意去重需要先对集合排序**) - + 从图中可以看出,同一树层上重复取2 就要过滤掉,同一树枝上就可以重复取2,因为同一树枝上元素的集合才是唯一子集! @@ -697,7 +695,3 @@ public class Solution ``` -- - - diff --git "a/problems/0093.345円244円215円345円216円237円IP345円234円260円345円235円200円.md" "b/problems/0093.345円244円215円345円216円237円IP345円234円260円345円235円200円.md" old mode 100644 new mode 100755 index a03a0e3b15..6fa732d0c1 --- "a/problems/0093.345円244円215円345円216円237円IP345円234円260円345円235円200円.md" +++ "b/problems/0093.345円244円215円345円216円237円IP345円234円260円345円235円200円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -56,7 +54,7 @@ 切割问题可以抽象为树型结构,如图: - + ### 回溯三部曲 @@ -108,7 +106,7 @@ if (pointNum == 3) { // 逗点数量为3时,分隔结束 如果不合法就结束本层循环,如图中剪掉的分支: - + 然后就是递归和回溯的过程: @@ -876,7 +874,3 @@ public class Solution -- - - diff --git "a/problems/0096.344円270円215円345円220円214円347円232円204円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" "b/problems/0096.344円270円215円345円220円214円347円232円204円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" old mode 100644 new mode 100755 index 25d79aff74..e5bc2b6b65 --- "a/problems/0096.344円270円215円345円220円214円347円232円204円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" +++ "b/problems/0096.344円270円215円345円220円214円347円232円204円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -14,7 +12,7 @@ 示例: - + ## 算法公开课 @@ -29,11 +27,11 @@ 了解了二叉搜索树之后,我们应该先举几个例子,画画图,看看有没有什么规律,如图: - + n为1的时候有一棵树,n为2有两棵树,这个是很直观的。 - + 来看看n为3的时候,有哪几种情况。 @@ -67,7 +65,7 @@ dp[3],就是 元素1为头结点搜索树的数量 + 元素2为头结点搜索 如图所示: - + 此时我们已经找到递推关系了,那么可以用动规五部曲再系统分析一遍。 @@ -120,7 +118,7 @@ for (int i = 1; i <= n; i++) { n为5时候的dp数组状态如图: - + 当然如果自己画图举例的话,基本举例到n为3就可以了,n为4的时候,画图已经比较麻烦了。 @@ -348,7 +346,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" "b/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" old mode 100644 new mode 100755 index fb4ca7d88d..990d3c8413 --- "a/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" +++ "b/problems/0098.351円252円214円350円257円201円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 98.验证二叉搜索树 @@ -18,7 +16,7 @@ * 节点的右子树只包含大于当前节点的数。 * 所有左子树和右子树自身必须也是二叉搜索树。 - + ## 算法公开课 @@ -104,7 +102,7 @@ if (root->val> root->left->val && root->val < root->right->val) { 例如: [10,5,15,null,null,6,20] 这个case: - + 节点10大于左节点5,小于右节点15,但右子树里出现了一个6 这就不符合了! @@ -807,7 +805,3 @@ public bool IsValidBST(TreeNode root) ``` -- - - diff --git "a/problems/0100.347円233円270円345円220円214円347円232円204円346円240円221円.md" "b/problems/0100.347円233円270円345円220円214円347円232円204円346円240円221円.md" old mode 100644 new mode 100755 index 7268b9f083..df1b55a462 --- "a/problems/0100.347円233円270円345円220円214円347円232円204円346円240円221円.md" +++ "b/problems/0100.347円233円270円345円220円214円347円232円204円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -14,9 +12,9 @@ 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 - + - + ## 思路 @@ -340,7 +338,3 @@ function isSameTree(p: TreeNode | null, q: TreeNode | null): boolean { -- - - diff --git "a/problems/0101.345円257円271円347円247円260円344円272円214円345円217円211円346円240円221円.md" "b/problems/0101.345円257円271円347円247円260円344円272円214円345円217円211円346円240円221円.md" old mode 100644 new mode 100755 index 31c24fc5aa..24e9e2684e --- "a/problems/0101.345円257円271円347円247円260円344円272円214円345円217円211円346円240円221円.md" +++ "b/problems/0101.345円257円271円347円247円260円344円272円214円345円217円211円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 101. 对称二叉树 @@ -11,7 +9,7 @@ 给定一个二叉树,检查它是否是镜像对称的。 - + ## 算法公开课 @@ -27,7 +25,7 @@ 比较的是两个子树的里侧和外侧的元素是否相等。如图所示: - + 那么遍历的顺序应该是什么样的呢? @@ -171,7 +169,7 @@ public: 通过队列来判断根节点的左子树和右子树的内侧和外侧是否相等,如动画所示: - + @@ -946,8 +944,4 @@ public bool IsSymmetric(TreeNode root) ``` -- - - diff --git "a/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md" "b/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md" old mode 100644 new mode 100755 index ce53e49af9..819153be97 --- "a/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md" +++ "b/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -28,7 +26,7 @@ - + @@ -39,7 +37,7 @@ 给你一个二叉树,请你返回其按 层序遍历 得到的节点值。 (即逐层地,从左到右访问所有节点)。 - + ### 思路 @@ -59,7 +57,7 @@ 使用队列实现二叉树广度优先遍历,动画如下: - + 这样就实现了层序从左到右遍历二叉树。 @@ -534,7 +532,7 @@ public IList- - - diff --git "a/problems/0104.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円244円247円346円267円261円345円272円246円.md" "b/problems/0104.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円244円247円346円267円261円345円272円246円.md" old mode 100644 new mode 100755 index fdc9009603..52d6d0e5fd --- "a/problems/0104.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円244円247円346円267円261円345円272円246円.md" +++ "b/problems/0104.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円244円247円346円267円261円345円272円246円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -20,7 +18,7 @@ 给定二叉树 [3,9,20,null,null,15,7], - + 返回它的最大深度 3 。 @@ -174,7 +172,7 @@ public: 在二叉树中,一层一层的来遍历二叉树,记录一下遍历的层数就是二叉树的深度,如图所示: - + 所以这道题的迭代法就是一道模板题,可以使用二叉树层序遍历的模板来解决的。 @@ -219,7 +217,7 @@ public: 例如,给定一个 3叉树 : - + 我们应返回其最大深度,3。 @@ -1195,7 +1193,3 @@ public int MaxDepth(TreeNode root) -- - - diff --git "a/problems/0106.344円273円216円344円270円255円345円272円217円344円270円216円345円220円216円345円272円217円351円201円215円345円216円206円345円272円217円345円210円227円346円236円204円351円200円240円344円272円214円345円217円211円346円240円221円.md" "b/problems/0106.344円273円216円344円270円255円345円272円217円344円270円216円345円220円216円345円272円217円351円201円215円345円216円206円345円272円217円345円210円227円346円236円204円351円200円240円344円272円214円345円217円211円346円240円221円.md" old mode 100644 new mode 100755 index bde61a7551..5253325835 --- "a/problems/0106.344円273円216円344円270円255円345円272円217円344円270円216円345円220円216円345円272円217円351円201円215円345円216円206円345円272円217円345円210円227円346円236円204円351円200円240円344円272円214円345円217円211円346円240円221円.md" +++ "b/problems/0106.344円273円216円344円270円255円345円272円217円344円270円216円345円220円216円345円272円217円351円201円215円345円216円206円345円272円217円345円210円227円346円236円204円351円200円240円344円272円214円345円217円211円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -27,7 +25,7 @@ * 后序遍历 postorder = [9,15,7,20,3] 返回如下的二叉树: - + ## 算法公开课 @@ -42,7 +40,7 @@ 流程如图: - + 那么代码应该怎么写呢? @@ -413,7 +411,7 @@ public: 中序遍历 inorder = [9,3,15,20,7] 返回如下的二叉树: - + ### 思路 @@ -556,7 +554,7 @@ public: 举一个例子: - + tree1 的前序遍历是[1 2 3], 后序遍历是[3 2 1]。 @@ -1351,7 +1349,3 @@ public TreeNode BuildTree(int[] inorder, int[] postorder) ``` -- - - diff --git "a/problems/0108.345円260円206円346円234円211円345円272円217円346円225円260円347円273円204円350円275円254円346円215円242円344円270円272円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" "b/problems/0108.345円260円206円346円234円211円345円272円217円346円225円260円347円273円204円350円275円254円346円215円242円344円270円272円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" old mode 100644 new mode 100755 index 4804ccd3b3..2df1c2615b --- "a/problems/0108.345円260円206円346円234円211円345円272円217円346円225円260円347円273円204円350円275円254円346円215円242円344円270円272円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" +++ "b/problems/0108.345円260円206円346円234円211円345円272円217円346円225円260円347円273円204円350円275円254円346円215円242円344円270円272円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 构造二叉搜索树,一不小心就平衡了 @@ -18,7 +16,7 @@ 示例: - + ## 算法公开课 @@ -42,7 +40,7 @@ 例如 有序数组[-10,-3,0,5,9] 就可以构造成这样的二叉搜索树,如图。 - + 上图中,是符合二叉搜索树的特性吧,如果要这么做的话,是不是本题意义就不大了,所以才强调是平衡二叉搜索树。 @@ -65,7 +63,7 @@ 如下两棵树,都是这个数组的平衡二叉搜索树: - + 如果要分割的数组长度为偶数的时候,中间元素为两个,是取左边元素 就是树1,取右边元素就是树2。 @@ -562,7 +560,3 @@ public TreeNode Traversal(int[] nums, int left, int right) -- - - diff --git "a/problems/0110.345円271円263円350円241円241円344円272円214円345円217円211円346円240円221円.md" "b/problems/0110.345円271円263円350円241円241円344円272円214円345円217円211円346円240円221円.md" old mode 100644 new mode 100755 index a4339ac3d7..d5b100ae80 --- "a/problems/0110.345円271円263円350円241円241円344円272円214円345円217円211円346円240円221円.md" +++ "b/problems/0110.345円271円263円350円241円241円344円272円214円345円217円211円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -21,7 +19,7 @@ 给定二叉树 [3,9,20,null,null,15,7] - + 返回 true 。 @@ -29,7 +27,7 @@ 给定二叉树 [1,2,2,3,3,null,null,4,4] - + 返回 false 。 @@ -48,7 +46,7 @@ 但leetcode中强调的深度和高度很明显是按照节点来计算的,如图: - + 关于根节点的深度究竟是1 还是 0,不同的地方有不一样的标准,leetcode的题目中都是以节点为一度,即根节点深度是1。但维基百科上定义用边为一度,即根节点的深度是0,我们暂时以leetcode为准(毕竟要在这上面刷题)。 @@ -998,7 +996,3 @@ public int GetHeight(TreeNode root) ``` -- - - diff --git "a/problems/0111.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円260円217円346円267円261円345円272円246円.md" "b/problems/0111.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円260円217円346円267円261円345円272円246円.md" old mode 100644 new mode 100755 index 708e0532f8..e1ee42657c --- "a/problems/0111.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円260円217円346円267円261円345円272円246円.md" +++ "b/problems/0111.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円345円260円217円346円267円261円345円272円246円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 和求最大深度一个套路? @@ -22,7 +20,7 @@ 给定二叉树 [3,9,20,null,null,15,7], - + 返回它的最小深度 2. @@ -48,7 +46,7 @@ 本题还有一个误区,在处理节点的过程中,最大深度很容易理解,最小深度就不那么好理解,如图: - + 这就重新审题了,题目中说的是:**最小深度是从根节点到最近叶子节点的最短路径上的节点数量。**注意是**叶子节点**。 @@ -90,7 +88,7 @@ return result; 这个代码就犯了此图中的误区: - + 如果这么求的话,没有左孩子的分支会算为最短深度。 @@ -752,7 +750,3 @@ public int MinDepth(TreeNode root) } ``` -- - - diff --git "a/problems/0112.350円267円257円345円276円204円346円200円273円345円222円214円.md" "b/problems/0112.350円267円257円345円276円204円346円200円273円345円222円214円.md" old mode 100644 new mode 100755 index 141967f593..73795bcfc9 --- "a/problems/0112.350円267円257円345円276円204円346円200円273円345円222円214円.md" +++ "b/problems/0112.350円267円257円345円276円204円346円200円273円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -17,7 +15,7 @@ 示例: 给定如下二叉树,以及目标和 sum = 22, - + 返回 true, 因为存在目标和为 22 的根节点到叶子节点的路径 5->4->11->2。 @@ -55,7 +53,7 @@ 如图所示: - + 图中可以看出,遍历的路线,并不要遍历整棵树,所以递归函数需要返回值,可以用bool类型表示。 @@ -232,7 +230,7 @@ public: 给定如下二叉树,以及目标和 sum = 22, - + ### 思路 @@ -241,7 +239,7 @@ public: 如图: - + 为了尽可能的把细节体现出来,我写出如下代码(**这份代码并不简洁,但是逻辑非常清晰**) @@ -1624,8 +1622,4 @@ public class Solution { ``` -- - - diff --git "a/problems/0115.344円270円215円345円220円214円347円232円204円345円255円220円345円272円217円345円210円227円.md" "b/problems/0115.344円270円215円345円220円214円347円232円204円345円255円220円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index cf24c4c180..499bf100e2 --- "a/problems/0115.344円270円215円345円220円214円347円232円204円345円255円220円345円272円217円345円210円227円.md" +++ "b/problems/0115.344円270円215円345円220円214円347円232円204円345円255円220円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 115.不同的子序列 @@ -14,7 +12,7 @@ 题目数据保证答案符合 32 位带符号整数范围。 - + 提示: @@ -72,7 +70,7 @@ dp[i][j]:以i-1为结尾的s子序列中出现以j-1为结尾的t的个数为d 从递推公式dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; 和 dp[i][j] = dp[i - 1][j]; 中可以看出dp[i][j] 是从上方和左上方推导而来,如图:,那么 dp[i][0] 和dp[0][j]是一定要初始化的。 - + 每次当初始化的时候,都要回顾一下dp[i][j]的定义,不要凭感觉初始化。 @@ -103,7 +101,7 @@ for (int j = 1; j <= t.size(); j++) dp[0][j] = 0; // 其实这行代码可以和 从递推公式dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]; 和 dp[i][j] = dp[i - 1][j]; 中可以看出dp[i][j]都是根据左上方和正上方推出来的。 - + 所以遍历的时候一定是从上到下,从左到右,这样保证dp[i][j]可以根据之前计算出来的数值进行计算。 @@ -125,7 +123,7 @@ for (int i = 1; i <= s.size(); i++) { 以s:"baegg",t:"bag"为例,推导dp数组状态如下: - + 如果写出来的代码怎么改都通过不了,不妨把dp数组打印出来,看一看,是不是这样的。 @@ -376,7 +374,3 @@ impl Solution { -- - - diff --git "a/problems/0116.345円241円253円345円205円205円346円257円217円344円270円252円350円212円202円347円202円271円347円232円204円344円270円213円344円270円200円344円270円252円345円217円263円344円276円247円350円212円202円347円202円271円346円214円207円351円222円210円.md" "b/problems/0116.345円241円253円345円205円205円346円257円217円344円270円252円350円212円202円347円202円271円347円232円204円344円270円213円344円270円200円344円270円252円345円217円263円344円276円247円350円212円202円347円202円271円346円214円207円351円222円210円.md" old mode 100644 new mode 100755 index 98bd4e41c1..88d3abc93e --- "a/problems/0116.345円241円253円345円205円205円346円257円217円344円270円252円350円212円202円347円202円271円347円232円204円344円270円213円344円270円200円344円270円252円345円217円263円344円276円247円350円212円202円347円202円271円346円214円207円351円222円210円.md" +++ "b/problems/0116.345円241円253円345円205円205円346円257円217円344円270円252円350円212円202円347円202円271円347円232円204円344円270円213円344円270円200円344円270円252円345円217円263円344円276円247円350円212円202円347円202円271円346円214円207円351円222円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 116. 填充每个节点的下一个右侧节点指针 @@ -28,7 +26,7 @@ struct Node { * 你只能使用常量级额外空间。 * 使用递归解题也符合要求,本题中递归程序占用的栈空间不算做额外的空间复杂度。 - + ## 思路 @@ -44,7 +42,7 @@ struct Node { 如图,假如当前操作的节点是cur: - + 最关键的点是可以通过上一层递归 搭出来的线,进行本次搭线。 @@ -489,8 +487,4 @@ public class Solution -- - - diff --git "a/problems/0121.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円.md" "b/problems/0121.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円.md" old mode 100644 new mode 100755 index f8092503e3..d12cbf2fe2 --- "a/problems/0121.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円.md" +++ "b/problems/0121.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 121. 买卖股票的最佳时机 @@ -131,7 +129,7 @@ dp[0][1]表示第0天不持有股票,不持有股票那么现金就是0,所 以示例1,输入:[7,1,5,3,6,4]为例,dp数组状态如下: - + dp[5][1]就是最终结果。 @@ -627,7 +625,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II.md" "b/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II.md" old mode 100644 new mode 100755 index 6663a66d12..0da4241931 --- "a/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II.md" +++ "b/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 122.买卖股票的最佳时机 II @@ -68,7 +66,7 @@ 如图: - + 一些同学陷入:第一天怎么就没有利润呢,第一天到底算不算的困惑中。 @@ -423,7 +421,3 @@ public class Solution ``` -- - - diff --git "a/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" "b/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" old mode 100644 new mode 100755 index 0dced9efd4..d8cb308b7e --- "a/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" +++ "b/problems/0122.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円II357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 122.买卖股票的最佳时机II @@ -477,7 +475,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0123.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円III.md" "b/problems/0123.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円III.md" old mode 100644 new mode 100755 index 1b7c09d214..063477cb5a --- "a/problems/0123.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円III.md" +++ "b/problems/0123.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円III.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 123.买卖股票的最佳时机III @@ -122,7 +120,7 @@ dp[i][4] = max(dp[i - 1][4], dp[i - 1][3] + prices[i]); 以输入[1,2,3,4,5]为例 - + 大家可以看到红色框为最后两次卖出的状态。 @@ -565,7 +563,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0127.345円215円225円350円257円215円346円216円245円351円276円231円.md" "b/problems/0127.345円215円225円350円257円215円346円216円245円351円276円231円.md" old mode 100644 new mode 100755 index 00d7d4cfc4..0204606056 --- "a/problems/0127.345円215円225円350円257円215円346円216円245円351円276円231円.md" +++ "b/problems/0127.345円215円225円350円257円215円346円216円245円351円276円231円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 127. 单词接龙 @@ -33,7 +31,7 @@ 以示例1为例,从这个图中可以看出 hit 到 cog的路线,不止一条,有三条,一条是最短的长度为5,两条长度为6。 - + 本题只需要求出最短路径的长度就可以了,不用找出路径。 @@ -360,7 +358,3 @@ function diffonechar(word1: string, word2: string): boolean { ``` -- - - diff --git "a/problems/0129.346円261円202円346円240円271円345円210円260円345円217円266円345円255円220円350円212円202円347円202円271円346円225円260円345円255円227円344円271円213円345円222円214円.md" "b/problems/0129.346円261円202円346円240円271円345円210円260円345円217円266円345円255円220円350円212円202円347円202円271円346円225円260円345円255円227円344円271円213円345円222円214円.md" old mode 100644 new mode 100755 index 90dfd0618f..1568a49469 --- "a/problems/0129.346円261円202円346円240円271円345円210円260円345円217円266円345円255円220円350円212円202円347円202円271円346円225円260円345円255円227円344円271円213円345円222円214円.md" +++ "b/problems/0129.346円261円202円346円240円271円345円210円260円345円217円266円345円255円220円350円212円202円347円202円271円346円225円260円345円255円227円344円271円213円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -83,7 +81,7 @@ int vectorToInt(const vector- - - diff --git "a/problems/0130.350円242円253円345円233円264円347円273円225円347円232円204円345円214円272円345円237円237円.md" "b/problems/0130.350円242円253円345円233円264円347円273円225円347円232円204円345円214円272円345円237円237円.md" old mode 100644 new mode 100755 index 8ef8d5b280..10d6585c4c --- "a/problems/0130.350円242円253円345円233円264円347円273円225円347円232円204円345円214円272円345円237円237円.md" +++ "b/problems/0130.350円242円253円345円233円264円347円273円225円347円232円204円345円214円272円345円237円237円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 130. 被围绕的区域 @@ -10,7 +8,7 @@ 给你一个 m x n 的矩阵 board ,由若干字符 'X' 和 'O' ,找到所有被 'X' 围绕的区域,并将这些区域里所有的 'O' 用 'X' 填充。 - + * 输入:board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]] * 输出:[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]] @@ -30,11 +28,11 @@ 步骤一:深搜或者广搜将地图周边的'O'全部改成'A',如图所示: - + 步骤二:在遍历地图,将'O'全部改成'X'(地图中间的'O'改成了'X'),将'A'改回'O'(保留的地图周边的'O'),如图所示: - + 整体C++代码如下,以下使用dfs实现,其实遍历方式dfs,bfs都是可以的。 @@ -793,7 +791,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0131.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円.md" "b/problems/0131.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円.md" old mode 100644 new mode 100755 index 4eca0ddf53..c76f1ce2f1 --- "a/problems/0131.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円.md" +++ "b/problems/0131.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 切割问题其实是一种组合问题! @@ -52,7 +50,7 @@ 所以切割问题,也可以抽象为一棵树形结构,如图: - + 递归用来纵向遍历,for循环用来横向遍历,切割线(就是图中的红线)切割到字符串的结尾位置,说明找到了一个切割方法。 @@ -78,7 +76,7 @@ void backtracking (const string& s, int startIndex) { * 递归函数终止条件 - + 从树形结构的图中可以看出:切割线切到了字符串最后面,说明找到了一种切割方法,此时就是本层递归的终止条件。 @@ -1007,7 +1005,3 @@ public class Solution -- - - diff --git "a/problems/0132.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円II.md" "b/problems/0132.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円II.md" old mode 100644 new mode 100755 index 85e047f2b7..8bbfa4ee10 --- "a/problems/0132.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円II.md" +++ "b/problems/0132.345円210円206円345円211円262円345円233円236円346円226円207円344円270円262円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -163,7 +161,7 @@ for (int i = s.size() - 1; i>= 0; i--) { 以输入:"aabc" 为例: - + 以上分析完毕,代码如下: @@ -373,7 +371,3 @@ var minCut = function(s) { -- - - diff --git "a/problems/0134.345円212円240円346円262円271円347円253円231円.md" "b/problems/0134.345円212円240円346円262円271円347円253円231円.md" old mode 100644 new mode 100755 index 0248760da6..5c8b0c3cc8 --- "a/problems/0134.345円212円240円346円262円271円347円253円231円.md" +++ "b/problems/0134.345円212円240円346円262円271円347円253円231円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 134. 加油站 @@ -146,7 +144,7 @@ i从0开始累加rest[i],和记为curSum,一旦curSum小于零,说明[0, i 如图: - + 那么为什么一旦[0,i] 区间和为负数,起始位置就可以是i+1呢,i+1后面就不会出现更大的负数? @@ -154,7 +152,7 @@ i从0开始累加rest[i],和记为curSum,一旦curSum小于零,说明[0, i 那有没有可能 [0,i] 区间 选某一个作为起点,累加到 i这里 curSum是不会小于零呢? 如图: - + 如果 curSum<0 说明 区间和1 + 区间和2 < 0, 那么 假设从上图中的位置开始计数curSum不会小于0的话,就是 区间和2>0。 @@ -709,7 +707,3 @@ public class Solution ``` -- - - diff --git "a/problems/0135.345円210円206円345円217円221円347円263円226円346円236円234円.md" "b/problems/0135.345円210円206円345円217円221円347円263円226円346円236円234円.md" old mode 100644 new mode 100755 index eb2081fe3f..9701f0f0c1 --- "a/problems/0135.345円210円206円345円217円221円347円263円226円346円236円234円.md" +++ "b/problems/0135.345円210円206円345円217円221円347円263円226円346円236円234円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 135. 分发糖果 @@ -58,7 +56,7 @@ for (int i = 1; i < ratings.size(); i++) { 如图: - + 再确定左孩子大于右孩子的情况(从后向前遍历) @@ -68,7 +66,7 @@ for (int i = 1; i < ratings.size(); i++) { 如果从前向后遍历,rating[5]与rating[4]的比较 就不能用上 rating[5]与rating[6]的比较结果了 。如图: - + **所以确定左孩子大于右孩子的情况一定要从后向前遍历!** @@ -84,7 +82,7 @@ for (int i = 1; i < ratings.size(); i++) { 如图: - + 所以该过程代码如下: @@ -401,7 +399,3 @@ public class Solution -- - - diff --git "a/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" "b/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" old mode 100644 new mode 100755 index 29748e2780..2015cb90c1 --- "a/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" +++ "b/problems/0139.345円215円225円350円257円215円346円213円206円345円210円206円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -182,7 +180,7 @@ dp[0]表示如果字符串为空的话,说明出现在字典里。 以输入: s = "leetcode", wordDict = ["leet", "code"]为例,dp状态如图: - + dp[s.size()]就是最终结果。 @@ -243,7 +241,7 @@ public: 使用用例:s = "applepenapple", wordDict = ["apple", "pen"],对应的dp数组状态如下: - + 最后dp[s.size()] = 0 即 dp[13] = 0 ,而不是1,因为先用 "apple" 去遍历的时候,dp[8]并没有被赋值为1 (还没用"pen"),所以 dp[13]也不能变成1。 @@ -565,7 +563,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0141.347円216円257円345円275円242円351円223円276円350円241円250円.md" "b/problems/0141.347円216円257円345円275円242円351円223円276円350円241円250円.md" old mode 100644 new mode 100755 index ac6565763f..d3583ba866 --- "a/problems/0141.347円216円257円345円275円242円351円223円276円350円241円250円.md" +++ "b/problems/0141.347円216円257円345円275円242円351円223円276円350円241円250円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 141. 环形链表 @@ -15,7 +13,7 @@ 如果链表中存在环,则返回 true 。 否则,返回 false 。 - + ## 思路 @@ -31,7 +29,7 @@ 会发现最终都是这种情况, 如下图: - + fast和slow各自再走一步, fast和slow就相遇了 @@ -40,7 +38,7 @@ fast和slow各自再走一步, fast和slow就相遇了 动画如下: - + C++代码如下 @@ -160,7 +158,3 @@ function hasCycle(head: ListNode | null): boolean { -- - - diff --git "a/problems/0142.347円216円257円345円275円242円351円223円276円350円241円250円II.md" "b/problems/0142.347円216円257円345円275円242円351円223円276円350円241円250円II.md" old mode 100644 new mode 100755 index 7cda58c396..4fd81ef0f5 --- "a/problems/0142.347円216円257円345円275円242円351円223円276円350円241円250円II.md" +++ "b/problems/0142.347円216円257円345円275円242円351円223円276円350円241円250円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -22,7 +20,7 @@ **说明**:不允许修改给定的链表。 - + ## 算法公开课 @@ -52,7 +50,7 @@ 会发现最终都是这种情况, 如下图: - + fast和slow各自再走一步, fast和slow就相遇了 @@ -61,7 +59,7 @@ fast和slow各自再走一步, fast和slow就相遇了 动画如下: - + ### 如果有环,如何找到这个环的入口 @@ -72,7 +70,7 @@ fast和slow各自再走一步, fast和slow就相遇了 环形入口节点到 fast指针与slow指针相遇节点 节点数为y。 从相遇节点 再到环形入口节点节点数为 z。 如图所示: - + 那么相遇时: slow指针走过的节点数为: `x + y`, @@ -105,7 +103,7 @@ fast指针走过的节点数:` x + y + n (y + z)`,n为fast指针在环内走 动画如下: - + 那么 n如果大于1是什么情况呢,就是fast指针在环形转n圈之后才遇到 slow指针。 @@ -156,20 +154,20 @@ public: 即文章[链表:环找到了,那入口呢?](https://programmercarl.com/0142.环形链表II.html)中如下的地方: - + 首先slow进环的时候,fast一定是先进环来了。 如果slow进环入口,fast也在环入口,那么把这个环展开成直线,就是如下图的样子: - + 可以看出如果slow 和 fast同时在环入口开始走,一定会在环入口3相遇,slow走了一圈,fast走了两圈。 重点来了,slow进环的时候,fast一定是在环的任意一个位置,如图: - + 那么fast指针走到环入口3的时候,已经走了k + n 个节点,slow相应的应该走了(k + n) / 2 个节点。 @@ -465,7 +463,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0143.351円207円215円346円216円222円351円223円276円350円241円250円.md" "b/problems/0143.351円207円215円346円216円222円351円223円276円350円241円250円.md" old mode 100644 new mode 100755 index ccddef5bf0..e7056913ee --- "a/problems/0143.351円207円215円346円216円222円351円223円276円350円241円250円.md" +++ "b/problems/0143.351円207円215円346円216円222円351円223円276円350円241円250円.md" @@ -1,14 +1,12 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 143.重排链表 [力扣题目链接](https://leetcode.cn/problems/reorder-list/submissions/) - + ## 思路 @@ -98,7 +96,7 @@ public: 如图: - + 这种方法,比较难,平均切割链表,看上去很简单,真正代码写的时候有很多细节,同时两个链表最后拼装整一个新的链表也有一些细节需要注意! @@ -689,7 +687,3 @@ void reorderList(struct ListNode* head){ ``` -- - - diff --git "a/problems/0150.351円200円206円346円263円242円345円205円260円350円241円250円350円276円276円345円274円217円346円261円202円345円200円274円.md" "b/problems/0150.351円200円206円346円263円242円345円205円260円350円241円250円350円276円276円345円274円217円346円261円202円345円200円274円.md" old mode 100644 new mode 100755 index bc73f6da0d..de56c51ff7 --- "a/problems/0150.351円200円206円346円263円242円345円205円260円350円241円250円350円276円276円345円274円217円346円261円202円345円200円274円.md" +++ "b/problems/0150.351円200円206円346円263円242円345円205円260円350円241円250円350円276円276円345円274円217円346円261円202円345円200円274円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 这不仅仅是一道好题,也展现出计算机的思考方式 @@ -80,7 +78,7 @@ 在进一步看,本题中每一个子表达式要得出一个结果,然后拿这个结果再进行运算,那么**这岂不就是一个相邻字符串消除的过程,和[1047.删除字符串中的所有相邻重复项](https://programmercarl.com/1047.删除字符串中的所有相邻重复项.html)中的对对碰游戏是不是就非常像了。** 如动画所示: - + 相信看完动画大家应该知道,这和[1047. 删除字符串中的所有相邻重复项](https://programmercarl.com/1047.删除字符串中的所有相邻重复项.html)是差不多的,只不过本题不要相邻元素做消除了,而是做运算! @@ -550,7 +548,3 @@ int evalRPN(char** tokens, int tokensSize) { } ``` -- - - diff --git "a/problems/0151.347円277円273円350円275円254円345円255円227円347円254円246円344円270円262円351円207円214円347円232円204円345円215円225円350円257円215円.md" "b/problems/0151.347円277円273円350円275円254円345円255円227円347円254円246円344円270円262円351円207円214円347円232円204円345円215円225円350円257円215円.md" old mode 100644 new mode 100755 index 3dbd59b916..b5246a7dbb --- "a/problems/0151.347円277円273円350円275円254円345円255円227円347円254円246円344円270円262円351円207円214円347円232円204円345円215円225円350円257円215円.md" +++ "b/problems/0151.347円277円273円350円275円254円345円255円227円347円254円246円344円270円262円351円207円214円347円232円204円345円215円225円350円257円215円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -1086,8 +1084,4 @@ public string ReverseWords(string s) { } ``` -- - - diff --git "a/problems/0160.347円233円270円344円272円244円351円223円276円350円241円250円.md" "b/problems/0160.347円233円270円344円272円244円351円223円276円350円241円250円.md" old mode 100644 new mode 100755 index d4422bd8ba..cdc58912fe --- "a/problems/0160.347円233円270円344円272円244円351円223円276円350円241円250円.md" +++ "b/problems/0160.347円233円270円344円272円244円351円223円276円350円241円250円.md" @@ -1,11 +1,5 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) 同:[链表:链表相交](https://programmercarl.com/面试题02.07.链表相交.html) -- - - diff --git "a/problems/0188.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円IV.md" "b/problems/0188.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円IV.md" old mode 100644 new mode 100755 index cbba12c9d1..350533d8c8 --- "a/problems/0188.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円IV.md" +++ "b/problems/0188.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円IV.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 188.买卖股票的最佳时机IV @@ -134,7 +132,7 @@ for (int j = 1; j < 2 * k; j += 2) { 以输入[1,2,3,4,5],k=2为例。 - + 最后一次卖出,一定是利润最大的,dp[prices.size() - 1][2 * k]即红色部分就是最后求解。 @@ -641,8 +639,4 @@ impl Solution { -- - - diff --git "a/problems/0189.346円227円213円350円275円254円346円225円260円347円273円204円.md" "b/problems/0189.346円227円213円350円275円254円346円225円260円347円273円204円.md" old mode 100644 new mode 100755 index e91109c692..976cbed4d1 --- "a/problems/0189.346円227円213円350円275円254円346円225円260円347円273円204円.md" +++ "b/problems/0189.346円227円213円350円275円254円346円225円260円347円273円204円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 189. 旋转数组 @@ -212,7 +210,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0198.346円211円223円345円256円266円345円212円253円350円210円215円.md" "b/problems/0198.346円211円223円345円256円266円345円212円253円350円210円215円.md" old mode 100644 new mode 100755 index 032204bbce..7c0aab8ec0 --- "a/problems/0198.346円211円223円345円256円266円345円212円253円350円210円215円.md" +++ "b/problems/0198.346円211円223円345円256円266円345円212円253円350円210円215円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 198.打家劫舍 @@ -89,7 +87,7 @@ for (int i = 2; i < nums.size(); i++) { 以示例二,输入[2,7,9,3,1]为例。 - + 红框dp[nums.size() - 1]为结果。 @@ -361,7 +359,3 @@ impl Solution { -- - - diff --git "a/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.345円271円277円346円220円234円347円211円210円.md" "b/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.345円271円277円346円220円234円347円211円210円.md" old mode 100644 new mode 100755 index 00e4efd894..7ae44b5222 --- "a/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.345円271円277円346円220円234円347円211円210円.md" +++ "b/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.345円271円277円346円220円234円347円211円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 200. 岛屿数量 @@ -15,7 +13,7 @@ 此外,你可以假设该网格的四条边均被水包围。 - + 提示: @@ -30,7 +28,7 @@ 也就是说斜角度链接是不算了, 例如示例二,是三个岛屿,如图: - + 这道题题目是 DFS,BFS,并查集,基础题目。 @@ -50,7 +48,7 @@ 如果从队列拿出节点,再去标记这个节点走过,就会发生下图所示的结果,会导致很多节点重复加入队列。 - + 超时写法 (从队列中取出节点再标记) @@ -410,7 +408,3 @@ impl Solution { ``` ``` -- - - diff --git "a/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.346円267円261円346円220円234円347円211円210円.md" "b/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.346円267円261円346円220円234円347円211円210円.md" old mode 100644 new mode 100755 index 4657920334..128007bb62 --- "a/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.346円267円261円346円220円234円347円211円210円.md" +++ "b/problems/0200.345円262円233円345円261円277円346円225円260円351円207円217円.346円267円261円346円220円234円347円211円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 200. 岛屿数量 @@ -14,7 +12,7 @@ 此外,你可以假设该网格的四条边均被水包围。 - + 提示: @@ -29,7 +27,7 @@ 也就是说斜角度链接是不算了, 例如示例二,是三个岛屿,如图: - + 这道题题目是 DFS,BFS,并查集,基础题目。 @@ -463,7 +461,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0202.345円277円253円344円271円220円346円225円260円.md" "b/problems/0202.345円277円253円344円271円220円346円225円260円.md" old mode 100644 new mode 100755 index 39cb39fa31..fdcadee97c --- "a/problems/0202.345円277円253円344円271円220円346円225円260円.md" +++ "b/problems/0202.345円277円253円344円271円220円346円225円260円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -558,7 +556,3 @@ def next_value(n) end ``` -- - - diff --git "a/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md" "b/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md" old mode 100644 new mode 100755 index 5a4bbb7423..ffe04a5b07 --- "a/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md" +++ "b/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -36,11 +34,11 @@ 这里以链表 1 4 2 4 来举例,移除元素4。 - + 如果使用C,C++编程语言的话,不要忘了还要从内存中删除这两个移除的节点, 清理节点内存之后如图: - + **当然如果使用java ,python的话就不用手动管理内存了。** @@ -58,16 +56,16 @@ 来看第一种操作:直接使用原来的链表来进行移除。 - + 移除头结点和移除其他节点的操作是不一样的,因为链表的其他节点都是通过前一个节点来移除当前节点,而头结点没有前一个节点。 所以头结点如何移除呢,其实只要将头结点向后移动一位就可以,这样就从链表中移除了一个头结点。 - + 依然别忘将原头结点从内存中删掉。 - + 这样移除了一个头结点,是不是发现,在单链表中移除头结点 和 移除其他节点的操作方式是不一样,其实在写代码的时候也会发现,需要单独写一段逻辑来处理移除头结点的情况。 @@ -78,7 +76,7 @@ 来看看如何设置一个虚拟头。依然还是在这个链表中,移除元素1。 - + 这里来给链表添加一个虚拟头结点为新的头结点,此时要移除这个旧头结点元素1。 @@ -808,7 +806,3 @@ end ``` -- - - diff --git "a/problems/0205.345円220円214円346円236円204円345円255円227円347円254円246円344円270円262円.md" "b/problems/0205.345円220円214円346円236円204円345円255円227円347円254円246円344円270円262円.md" old mode 100644 new mode 100755 index e416d9ceda..ba255e0685 --- "a/problems/0205.345円220円214円346円236円204円345円255円227円347円254円246円344円270円262円.md" +++ "b/problems/0205.345円220円214円346円236円204円345円255円227円347円254円246円344円270円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 205. 同构字符串 @@ -180,7 +178,3 @@ function isIsomorphic(s: string, t: string): boolean { -- - - diff --git "a/problems/0206.347円277円273円350円275円254円351円223円276円350円241円250円.md" "b/problems/0206.347円277円273円350円275円254円351円223円276円350円241円250円.md" old mode 100644 new mode 100755 index 430bebe59b..e49037dd2b --- "a/problems/0206.347円277円273円350円275円254円351円223円276円350円241円250円.md" +++ "b/problems/0206.347円277円273円350円275円254円351円223円276円350円241円250円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 反转链表的写法很简单,一些同学甚至可以背下来但过一阵就忘了该咋写,主要是因为没有理解真正的反转过程。 @@ -29,7 +27,7 @@ 其实只需要改变链表的next指针的指向,直接将链表反转 ,而不用重新定义一个新的链表,如图所示: - + 之前链表的头节点是元素1, 反转之后头结点就是元素5 ,这里并没有添加或者删除节点,仅仅是改变next指针的方向。 @@ -37,7 +35,7 @@ 我们拿有示例中的链表来举例,如动画所示:(纠正:动画应该是先移动pre,在移动cur) - + 首先定义一个cur指针,指向头结点,再定义一个pre指针,初始化为null。 @@ -739,7 +737,3 @@ public ListNode reverseList(ListNode head) { > 采用这种方法需要注意一点。就是当整个出栈循环结束以后,cur正好指向原来链表的第一个结点,而此时结点1中的next指向的是结点2,因此最后还需要`cur.next = null`  -- - - diff --git "a/problems/0207.350円257円276円347円250円213円350円241円250円.md" "b/problems/0207.350円257円276円347円250円213円350円241円250円.md" index dff0b18eb0..f992c72b89 100644 --- "a/problems/0207.350円257円276円347円250円213円350円241円250円.md" +++ "b/problems/0207.350円257円276円347円250円213円350円241円250円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) 拓扑排序指的是一种 解决问题的大体思路, 而具体算法,可能是 广搜 可能是深搜。 @@ -59,7 +57,3 @@ public: } }; ``` -- - - diff --git "a/problems/0209.351円225円277円345円272円246円346円234円200円345円260円217円347円232円204円345円255円220円346円225円260円347円273円204円.md" "b/problems/0209.351円225円277円345円272円246円346円234円200円345円260円217円347円232円204円345円255円220円346円225円260円347円273円204円.md" old mode 100644 new mode 100755 index c6d89976d0..c8440c4a67 --- "a/problems/0209.351円225円277円345円272円246円346円234円200円345円260円217円347円232円204円345円255円220円346円225円260円347円273円204円.md" +++ "b/problems/0209.351円225円277円345円272円246円346円234円200円345円260円217円347円232円204円345円255円220円346円225円260円347円273円204円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 209.长度最小的子数组 @@ -68,7 +66,7 @@ public: 接下来就开始介绍数组操作中另一个重要的方法:**滑动窗口**。 -所谓滑动窗口,**就是不断的调节子序列的起始位置和终止位置,从而得出我们要想的结果**。 +所谓滑动窗口,**就是不断的调节子序列的起始位置和终止位置,从而得出我们想要的结果**。 在暴力解法中,是一个for循环滑动窗口的起始位置,一个for循环为滑动窗口的终止位置,用两个for循环 完成了一个不断搜索区间的过程。 @@ -86,7 +84,7 @@ public: 这里还是以题目中的示例来举例,s=7, 数组是 2,3,1,2,4,3,来看一下查找的过程: - + 最后找到 4,3 是最短距离。 @@ -106,7 +104,7 @@ public: 解题的关键在于 窗口的起始位置如何移动,如图所示: - + 可以发现**滑动窗口的精妙之处在于根据当前子序列和大小的情况,不断调节子序列的起始位置。从而将O(n^2)暴力解法降为O(n)。** @@ -558,7 +556,3 @@ public class Solution { } } ``` -- - - diff --git "a/problems/0210.350円257円276円347円250円213円350円241円250円II.md" "b/problems/0210.350円257円276円347円250円213円350円241円250円II.md" index 2d2e242941..b0d9fe8a9e 100644 --- "a/problems/0210.350円257円276円347円250円213円350円241円250円II.md" +++ "b/problems/0210.350円257円276円347円250円213円350円241円250円II.md" @@ -1,3 +1,6 @@ +* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) ```CPP class Solution { diff --git "a/problems/0213.346円211円223円345円256円266円345円212円253円350円210円215円II.md" "b/problems/0213.346円211円223円345円256円266円345円212円253円350円210円215円II.md" old mode 100644 new mode 100755 index 05ebd1ad09..6f2fdd0610 --- "a/problems/0213.346円211円223円345円256円266円345円212円253円350円210円215円II.md" +++ "b/problems/0213.346円211円223円345円256円266円345円212円253円350円210円215円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 213.打家劫舍II @@ -44,15 +42,15 @@ * 情况一:考虑不包含首尾元素 - + * 情况二:考虑包含首元素,不包含尾元素 - + * 情况三:考虑包含尾元素,不包含首元素 - + **注意我这里用的是"考虑"**,例如情况三,虽然是考虑包含尾元素,但不一定要选尾部元素! 对于情况三,取nums[1] 和 nums[3]就是最大的。 @@ -367,7 +365,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0216.347円273円204円345円220円210円346円200円273円345円222円214円III.md" "b/problems/0216.347円273円204円345円220円210円346円200円273円345円222円214円III.md" old mode 100644 new mode 100755 index 3d7f2d0c03..5ef5b5e67c --- "a/problems/0216.347円273円204円345円220円210円346円200円273円345円222円214円III.md" +++ "b/problems/0216.347円273円204円345円220円210円346円200円273円345円222円214円III.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -47,7 +45,7 @@ 选取过程如图: - + 图中,可以看出,只有最后取到集合(1,3)和为4 符合条件。 @@ -110,7 +108,7 @@ if (path.size() == k) { 本题和[77. 组合](https://programmercarl.com/0077.组合.html)区别之一就是集合固定的就是9个数[1,...,9],所以for循环固定i<=9 如图: - + 处理过程就是 path收集每次选取的元素,相当于树型结构里的边,sum来统计path里元素的总和。 @@ -168,7 +166,7 @@ public: 这道题目,剪枝操作其实是很容易想到了,想必大家看上面的树形图的时候已经想到了。 如图: - + 已选元素总和如果已经大于n(图中数值为4)了,那么往后遍历就没有意义了,直接剪掉。 @@ -367,7 +365,7 @@ class Solution: def backtracking(self, targetSum, k, currentSum, startIndex, path, result): if currentSum> targetSum: # 剪枝操作 - return # 如果path的长度等于k但currentSum不等于targetSum,则直接返回 + return # 如果currentSum已经超过targetSum,则直接返回 if len(path) == k: if currentSum == targetSum: result.append(path[:]) @@ -739,7 +737,3 @@ public class Solution -- - - diff --git "a/problems/0222.345円256円214円345円205円250円344円272円214円345円217円211円346円240円221円347円232円204円350円212円202円347円202円271円344円270円252円346円225円260円.md" "b/problems/0222.345円256円214円345円205円250円344円272円214円345円217円211円346円240円221円347円232円204円350円212円202円347円202円271円344円270円252円346円225円260円.md" old mode 100644 new mode 100755 index 8d7779f989..eaf4eab2c9 --- "a/problems/0222.345円256円214円345円205円250円344円272円214円345円217円211円346円240円221円347円232円204円350円212円202円347円202円271円344円270円252円346円225円260円.md" +++ "b/problems/0222.345円256円214円345円205円250円344円272円214円345円217円211円346円240円221円347円232円204円350円212円202円347円202円271円344円270円252円346円225円260円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 222.完全二叉树的节点个数 @@ -155,7 +153,7 @@ public: 我来举一个典型的例子如题: - + 完全二叉树只有两种情况,情况一:就是满二叉树,情况二:最后一层叶子节点没有满。 @@ -164,10 +162,10 @@ public: 对于情况二,分别递归左孩子,和右孩子,递归到某一深度一定会有左孩子或者右孩子为满二叉树,然后依然可以按照情况1来计算。 完全二叉树(一)如图: - + 完全二叉树(二)如图: - + 可以看出如果整个树不是满二叉树,就递归其左右孩子,直到遇到满二叉树为止,用公式计算这个子树(满二叉树)的节点数量。 @@ -175,15 +173,15 @@ public: 在完全二叉树中,如果递归向左遍历的深度等于递归向右遍历的深度,那说明就是满二叉树。如图: - + 在完全二叉树中,如果递归向左遍历的深度不等于递归向右遍历的深度,则说明不是满二叉树,如图: - + 那有录友说了,这种情况,递归向左遍历的深度等于递归向右遍历的深度,但也不是满二叉树,如题: - + 如果这么想,大家就是对 完全二叉树理解有误区了,**以上这棵二叉树,它根本就不是一个完全二叉树**! @@ -894,7 +892,3 @@ public int CountNodes(TreeNode root) ``` -- - - diff --git "a/problems/0225.347円224円250円351円230円237円345円210円227円345円256円236円347円216円260円346円240円210円.md" "b/problems/0225.347円224円250円351円230円237円345円210円227円345円256円236円347円216円260円346円240円210円.md" old mode 100644 new mode 100755 index 73d9db1b16..72dfd2aacf --- "a/problems/0225.347円224円250円351円230円237円345円210円227円345円256円236円347円216円260円346円240円210円.md" +++ "b/problems/0225.347円224円250円351円230円237円345円210円227円345円256円236円347円216円260円346円240円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -62,7 +60,7 @@ queue.pop(); queue.empty(); ``` - + 详细如代码注释所示: @@ -1367,7 +1365,3 @@ void myStackFree(MyStack* obj) { ``` -- - - diff --git "a/problems/0226.347円277円273円350円275円254円344円272円214円345円217円211円346円240円221円.md" "b/problems/0226.347円277円273円350円275円254円344円272円214円345円217円211円346円240円221円.md" old mode 100644 new mode 100755 index c34ca4bfcb..67a1a59338 --- "a/problems/0226.347円277円273円350円275円254円344円272円214円345円217円211円346円240円221円.md" +++ "b/problems/0226.347円277円273円350円275円254円344円272円214円345円217円211円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 226.翻转二叉树 @@ -12,7 +10,7 @@ 翻转一棵二叉树。 - + 这道题目背后有一个让程序员心酸的故事,听说 Homebrew的作者Max Howell,就是因为没在白板上写出翻转二叉树,最后被Google拒绝了。(真假不做判断,全当一个乐子哈) @@ -37,7 +35,7 @@ 如果要从整个树来看,翻转还真的挺复杂,整个树以中间分割线进行翻转,如图: - + 可以发现想要翻转它,其实就把每一个节点的左右孩子交换一下就可以了。 @@ -57,7 +55,7 @@ 我们下文以前序遍历为例,通过动画来看一下翻转的过程: - + 我们来看一下递归三部曲: @@ -1022,7 +1020,3 @@ public TreeNode InvertTree(TreeNode root) { ``` -- - - diff --git "a/problems/0232.347円224円250円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.md" "b/problems/0232.347円224円250円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.md" old mode 100644 new mode 100755 index 657567cfdf..56698e023f --- "a/problems/0232.347円224円250円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.md" +++ "b/problems/0232.347円224円250円346円240円210円345円256円236円347円216円260円351円230円237円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 工作上一定没人这么搞,但是考察对栈、队列理解程度的好题 @@ -59,7 +57,7 @@ queue.pop();**注意此时的输出栈的操作** queue.pop(); queue.empty(); - + 在push数据的时候,只要数据放进输入栈就好,**但在pop的时候,操作就复杂一些,输出栈如果为空,就把进栈数据全部导入进来(注意是全部导入)**,再从出栈弹出数据,如果输出栈不为空,则直接从出栈弹出数据就可以了。 @@ -691,7 +689,3 @@ impl MyQueue { } ``` -- - - diff --git "a/problems/0234.345円233円236円346円226円207円351円223円276円350円241円250円.md" "b/problems/0234.345円233円236円346円226円207円351円223円276円350円241円250円.md" old mode 100644 new mode 100755 index 1356b7da3b..6248861d94 --- "a/problems/0234.345円233円236円346円226円207円351円223円276円350円241円250円.md" +++ "b/problems/0234.345円233円236円346円226円207円351円223円276円350円241円250円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 234.回文链表 @@ -89,7 +87,7 @@ public: 如图所示: - + 代码如下: @@ -429,7 +427,3 @@ function reverseList(head: ListNode | null): ListNode | null { -- - - diff --git "a/problems/0235.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" "b/problems/0235.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" old mode 100644 new mode 100755 index 3911261a53..a1fe78d169 --- "a/problems/0235.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" +++ "b/problems/0235.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 235. 二叉搜索树的最近公共祖先 @@ -16,7 +14,7 @@ 例如,给定如下二叉搜索树: root = [6,2,8,0,4,7,9,null,null,3,5] - + 示例 1: @@ -54,7 +52,7 @@ 如图,我们从根节点搜索,第一次遇到 cur节点是数值在[q, p]区间中,即 节点5,此时可以说明 q 和 p 一定分别存在于 节点 5的左子树,和右子树中。 - + 此时节点5是不是最近公共祖先? 如果 从节点5继续向左遍历,那么将错过成为p的祖先, 如果从节点5继续向右遍历则错过成为q的祖先。 @@ -66,7 +64,7 @@ 如图所示:p为节点6,q为节点9 - + 可以看出直接按照指定的方向,就可以找到节点8,为最近公共祖先,而且不需要遍历整棵树,找到结果直接返回! @@ -548,7 +546,3 @@ public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) -- - - diff --git "a/problems/0236.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" "b/problems/0236.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" old mode 100644 new mode 100755 index 8cd505a829..5044e3ba00 --- "a/problems/0236.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" +++ "b/problems/0236.344円272円214円345円217円211円346円240円221円347円232円204円346円234円200円350円277円221円345円205円254円345円205円261円347円245円226円345円205円210円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 本来是打算将二叉树和二叉搜索树的公共祖先问题一起讲,后来发现篇幅过长了,只能先说一说二叉树的公共祖先问题。 @@ -18,7 +16,7 @@ 例如,给定如下二叉树: root = [3,5,1,6,2,0,8,null,null,7,4] - + 示例 1: 输入: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 @@ -53,7 +51,7 @@ **首先最容易想到的一个情况:如果找到一个节点,发现左子树出现结点p,右子树出现节点q,或者 左子树出现结点q,右子树出现节点p,那么该节点就是节点p和q的最近公共祖先。** 即情况一: - + 判断逻辑是 如果递归遍历遇到q,就将q返回,遇到p 就将p返回,那么如果 左右子树的返回值都不为空,说明此时的中节点,一定是q 和p 的最近祖先。 @@ -63,7 +61,7 @@ **但是很多人容易忽略一个情况,就是节点本身p(q),它拥有一个子孙节点q(p)。** 情况二: - + 其实情况一 和 情况二 代码实现过程都是一样的,也可以说,实现情况一的逻辑,顺便包含了情况二。 @@ -131,7 +129,7 @@ left与right的逻辑处理; // 中 如图: - + 就像图中一样直接返回7。 @@ -164,7 +162,7 @@ TreeNode* right = lowestCommonAncestor(root->right, p, q); 如图: - + 图中节点10的左子树返回null,右子树返回目标值7,那么此时节点10的处理逻辑就是把右子树的返回值(最近公共祖先7)返回上去! @@ -185,7 +183,7 @@ else { // (left == NULL && right == NULL) 那么寻找最小公共祖先,完整流程图如下: - + **从图中,大家可以看到,我们是如何回溯遍历整棵二叉树,将结果返回给头结点的!** @@ -491,7 +489,3 @@ public TreeNode LowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) ``` -- - - diff --git "a/problems/0239.346円273円221円345円212円250円347円252円227円345円217円243円346円234円200円345円244円247円345円200円274円.md" "b/problems/0239.346円273円221円345円212円250円347円252円227円345円217円243円346円234円200円345円244円247円345円200円274円.md" old mode 100644 new mode 100755 index 651e4da40c..5ea810104d --- "a/problems/0239.346円273円221円345円212円250円347円252円227円345円217円243円346円234円200円345円244円247円345円200円274円.md" +++ "b/problems/0239.346円273円221円345円212円250円347円252円227円345円217円243円346円234円200円345円244円247円345円200円274円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -20,7 +18,7 @@ 你能在线性时间复杂度内解决此题吗? - + 提示: @@ -84,7 +82,7 @@ public: 动画如下: - + 对于窗口里的元素{2, 3, 5, 1 ,4},单调队列里只维护{5, 4} 就够了,保持单调队列里单调递减,此时队列出口元素就是窗口里最大元素。 @@ -100,7 +98,7 @@ public: 为了更直观的感受到单调队列的工作过程,以题目示例为例,输入: nums = [1,3,-1,-3,5,3,6,7], 和 k = 3,动画如下: - + 那么我们用什么数据结构来实现这个单调队列呢? @@ -922,8 +920,4 @@ int* maxSlidingWindow(int* nums, int numsSize, int k, int* returnSize) { ``` -- - - diff --git "a/problems/0242.346円234円211円346円225円210円347円232円204円345円255円227円346円257円215円345円274円202円344円275円215円350円257円215円.md" "b/problems/0242.346円234円211円346円225円210円347円232円204円345円255円227円346円257円215円345円274円202円344円275円215円350円257円215円.md" old mode 100644 new mode 100755 index 61488f03fd..0a37ea26cc --- "a/problems/0242.346円234円211円346円225円210円347円232円204円345円255円227円346円257円215円345円274円202円344円275円215円350円257円215円.md" +++ "b/problems/0242.346円234円211円346円225円210円347円232円204円345円255円227円346円257円215円345円274円202円344円275円215円350円257円215円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 数组就是简单的哈希表,但是数组的大小可不是无限开辟的 @@ -44,7 +42,7 @@ 操作动画如下: - + 定义一个数组叫做record用来上记录字符串s里字符出现的次数。 @@ -416,7 +414,3 @@ bool isAnagram(char* s, char* t) { -- - - diff --git "a/problems/0257.344円272円214円345円217円211円346円240円221円347円232円204円346円211円200円346円234円211円350円267円257円345円276円204円.md" "b/problems/0257.344円272円214円345円217円211円346円240円221円347円232円204円346円211円200円346円234円211円350円267円257円345円276円204円.md" old mode 100644 new mode 100755 index fdaa87f896..4a66c816bc --- "a/problems/0257.344円272円214円345円217円211円346円240円221円347円232円204円346円211円200円346円234円211円350円267円257円345円276円204円.md" +++ "b/problems/0257.344円272円214円345円217円211円346円240円221円347円232円204円346円211円200円346円234円211円350円267円257円345円276円204円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 以为只用了递归,其实还用了回溯 @@ -16,7 +14,7 @@ 说明: 叶子节点是指没有子节点的节点。 示例: - + ## 算法公开课 @@ -30,7 +28,7 @@ 前序遍历以及回溯的过程如图: - + 我们先使用递归的方式,来做前序遍历。**要知道递归和回溯就是一家的,本题也需要回溯。** @@ -317,7 +315,7 @@ public: 其实关键还在于 参数,使用的是 `string path`,这里并没有加上引用`&` ,即本层递归中,path + 该节点数值,但该层递归结束,上一层path的数值并不会受到任何影响。 如图所示: - + 节点4 的path,在遍历到节点3,path+3,遍历节点3的递归结束之后,返回节点4(回溯的过程),path并不会把3加上。 @@ -938,7 +936,3 @@ public void Traversal(TreeNode node, List- - - diff --git "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" old mode 100644 new mode 100755 index dc5a7e9ec9..7c5d7c9c9f --- "a/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" +++ "b/problems/0279.345円256円214円345円205円250円345円271円263円346円226円271円346円225円260円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 279.完全平方数 @@ -95,7 +93,7 @@ for (int i = 0; i <= n; i++) { // 遍历背包 已输入n为5例,dp状态图如下: - + dp[0] = 0 dp[1] = min(dp[0] + 1) = 1 @@ -479,7 +477,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0283.347円247円273円345円212円250円351円233円266円.md" "b/problems/0283.347円247円273円345円212円250円351円233円266円.md" old mode 100644 new mode 100755 index cbce029576..e25525684e --- "a/problems/0283.347円247円273円345円212円250円351円233円266円.md" +++ "b/problems/0283.347円247円273円345円212円250円351円233円266円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 283. 移动零:动态规划:一样的套路,再求一次完全平方数 @@ -34,7 +32,7 @@ 如动画所示: - + C++代码如下: @@ -186,7 +184,3 @@ impl Solution { -- - - diff --git "a/problems/0300.346円234円200円351円225円277円344円270円212円345円215円207円345円255円220円345円272円217円345円210円227円.md" "b/problems/0300.346円234円200円351円225円277円344円270円212円345円215円207円345円255円220円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index 442938c06f..06adfd950d --- "a/problems/0300.346円234円200円351円225円277円344円270円212円345円215円207円345円255円220円345円272円217円345円210円227円.md" +++ "b/problems/0300.346円234円200円351円225円277円344円270円212円345円215円207円345円255円220円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 300.最长递增子序列 @@ -87,7 +85,7 @@ for (int i = 1; i < nums.size(); i++) { 输入:[0,1,0,3,2],dp数组的变化如下: - + 如果代码写出来,但一直AC不了,那么就把dp数组打印出来,看看对不对! @@ -361,7 +359,3 @@ func lengthOfLIS(nums: Array- - - diff --git "a/problems/0309.346円234円200円344円275円263円344円271円260円345円215円226円350円202円241円347円245円250円346円227円266円346円234円272円345円220円253円345円206円267円345円206円273円346円234円237円.md" "b/problems/0309.346円234円200円344円275円263円344円271円260円345円215円226円350円202円241円347円245円250円346円227円266円346円234円272円345円220円253円345円206円267円345円206円273円346円234円237円.md" old mode 100644 new mode 100755 index b98a416cc1..d396e521b3 --- "a/problems/0309.346円234円200円344円275円263円344円271円260円345円215円226円350円202円241円347円245円250円346円227円266円346円234円272円345円220円253円345円206円267円345円206円273円346円234円237円.md" +++ "b/problems/0309.346円234円200円344円275円263円344円271円260円345円215円226円350円202円241円347円245円250円346円227円266円346円234円272円345円220円253円345円206円267円345円206円273円346円234円237円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 309.最佳买卖股票时机含冷冻期 @@ -49,7 +47,7 @@ dp[i][j],第i天状态为j,所剩的最多现金为dp[i][j]。 * 状态三:今天卖出股票 * 状态四:今天为冷冻期状态,但冷冻期状态不可持续,只有一天! - + j的状态为: @@ -138,7 +136,7 @@ dp[i][3] = dp[i - 1][2]; 以 [1,2,3,0,2] 为例,dp数组如下: - + 最后结果是取 状态二,状态三,和状态四的最大值,不少同学会把状态四忘了,状态四是冷冻期,最后一天如果是冷冻期也可能是最大值。 @@ -603,8 +601,4 @@ impl Solution { ``` -- - - diff --git "a/problems/0322.351円233円266円351円222円261円345円205円221円346円215円242円.md" "b/problems/0322.351円233円266円351円222円261円345円205円221円346円215円242円.md" old mode 100644 new mode 100755 index e55e20bedf..f3a0a07dd9 --- "a/problems/0322.351円233円266円351円222円261円345円205円221円346円215円242円.md" +++ "b/problems/0322.351円233円266円351円222円261円345円205円221円346円215円242円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 322. 零钱兑换 @@ -106,7 +104,7 @@ dp[0] = 0; 以输入:coins = [1, 2, 5], amount = 5为例 - + dp[amount]为最终结果。 @@ -499,7 +497,3 @@ function coinChange(coins: number[], amount: number): number { ``` -- - - diff --git "a/problems/0332.351円207円215円346円226円260円345円256円211円346円216円222円350円241円214円347円250円213円.md" "b/problems/0332.351円207円215円346円226円260円345円256円211円346円216円222円350円241円214円347円250円213円.md" old mode 100644 new mode 100755 index 78e1407419..1168277a8d --- "a/problems/0332.351円207円215円346円226円260円345円256円211円346円216円222円350円241円214円347円250円213円.md" +++ "b/problems/0332.351円207円215円346円226円260円345円256円211円346円216円222円350円241円214円347円250円213円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 这也可以用回溯法? 其实深搜和回溯也是相辅相成的,毕竟都用递归。 @@ -59,7 +57,7 @@ 对于死循环,我来举一个有重复机场的例子: - + 为什么要举这个例子呢,就是告诉大家,出发机场和到达机场也会重复的,**如果在解题的过程中没有对集合元素处理好,就会死循环。** @@ -113,7 +111,7 @@ void backtracking(参数) { 本题以输入:[["JFK", "KUL"], ["JFK", "NRT"], ["NRT", "JFK"]为例,抽象为树形结构如下: - + 开始回溯三部曲讲解: @@ -139,7 +137,7 @@ bool backtracking(int ticketNum, vector- - - diff --git "a/problems/0337.346円211円223円345円256円266円345円212円253円350円210円215円III.md" "b/problems/0337.346円211円223円345円256円266円345円212円253円350円210円215円III.md" old mode 100644 new mode 100755 index a3130df7ee..44af86bb4c --- "a/problems/0337.346円211円223円345円256円266円345円212円253円350円210円215円III.md" +++ "b/problems/0337.346円211円223円345円256円266円345円212円253円350円210円215円III.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 337.打家劫舍 III @@ -14,7 +12,7 @@ 计算在不触动警报的情况下,小偷一晚能够盗取的最高金额。 - + ## 算法公开课 @@ -179,7 +177,7 @@ return {val2, val1}; 以示例1为例,dp数组状态如下:(**注意用后序遍历的方式推导**) - + **最后头结点就是 取下标0 和 下标1的最大值就是偷得的最大金钱**。 @@ -623,7 +621,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" "b/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" old mode 100644 new mode 100755 index 5d0110f67e..c9467e361f --- "a/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" +++ "b/problems/0343.346円225円264円346円225円260円346円213円206円345円210円206円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 343. 整数拆分 @@ -129,7 +127,7 @@ for (int i = 3; i <= n ; i++) { 举例当n为10 的时候,dp数组里的数值,如下: - + 以上动规五部曲分析完毕,C++代码如下: @@ -564,7 +562,3 @@ public class Solution ``` -- - - diff --git "a/problems/0344.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円.md" "b/problems/0344.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円.md" old mode 100644 new mode 100755 index 793c9af362..cadb31c97b --- "a/problems/0344.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円.md" +++ "b/problems/0344.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -71,7 +69,7 @@ 以字符串`hello`为例,过程如下: - + 不难写出如下C++代码: @@ -429,7 +427,3 @@ object Solution { } } ``` -- - - diff --git "a/problems/0347.345円211円215円K344円270円252円351円253円230円351円242円221円345円205円203円347円264円240円.md" "b/problems/0347.345円211円215円K344円270円252円351円253円230円351円242円221円345円205円203円347円264円240円.md" old mode 100644 new mode 100755 index cca9b0edce..fa7d6155a5 --- "a/problems/0347.345円211円215円K344円270円252円351円253円230円351円242円221円345円205円203円347円264円240円.md" +++ "b/problems/0347.345円211円215円K344円270円252円351円253円230円351円242円221円345円205円203円347円264円240円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 前K个大数问题,老生常谈,不得不谈 @@ -72,7 +70,7 @@ 寻找前k个最大元素流程如图所示:(图中的频率只有三个,所以正好构成一个大小为3的小顶堆,如果频率更多一些,则用这个小顶堆进行扫描) - + 我们来看一下C++代码: @@ -609,8 +607,4 @@ impl Solution { ``` -- - - diff --git "a/problems/0349.344円270円244円344円270円252円346円225円260円347円273円204円347円232円204円344円272円244円351円233円206円.md" "b/problems/0349.344円270円244円344円270円252円346円225円260円347円273円204円347円232円204円344円272円244円351円233円206円.md" old mode 100644 new mode 100755 index 93fa09318a..77e895da61 --- "a/problems/0349.344円270円244円344円270円252円346円225円260円347円273円204円347円232円204円344円272円244円351円233円206円.md" +++ "b/problems/0349.344円270円244円344円270円252円346円225円260円347円273円204円347円232円204円344円272円244円351円233円206円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -16,7 +14,7 @@ 题意:给定两个数组,编写一个函数来计算它们的交集。 - + **说明:** 输出结果中的每个元素一定是唯一的。 @@ -53,7 +51,7 @@ std::set和std::multiset底层实现都是红黑树,std::unordered_set的底 思路如图所示: - + C++代码如下: @@ -544,8 +542,4 @@ end * [350.两个数组的交集 II](https://leetcode.cn/problems/intersection-of-two-arrays-ii/) -- - - diff --git "a/problems/0376.346円221円206円345円212円250円345円272円217円345円210円227円.md" "b/problems/0376.346円221円206円345円212円250円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index e2ea99046b..1be9cb4178 --- "a/problems/0376.346円221円206円345円212円250円345円272円217円345円210円227円.md" +++ "b/problems/0376.346円221円206円345円212円250円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 376. 摆动序列 @@ -48,7 +46,7 @@ 用示例二来举例,如图所示: - + **局部最优:删除单调坡度上的节点(不包括单调坡度两端的节点),那么这个坡度就可以有两个局部峰值**。 @@ -74,13 +72,13 @@ 例如 [1,2,2,2,2,1]这样的数组,如图: - + 它的摇摆序列长度是多少呢? **其实是长度是 3**,也就是我们在删除的时候 要不删除左面的三个 2,要不就删除右边的三个 2。 如图,可以统一规则,删除左边的三个 2: - + 在图中,当 i 指向第一个 2 的时候,`prediff> 0 && curdiff = 0` ,当 i 指向最后一个 2 的时候 `prediff = 0 && curdiff < 0`。 @@ -108,7 +106,7 @@ 那么为了规则统一,针对序列[2,5],可以假设为[2,2,5],这样它就有坡度了即 preDiff = 0,如图: - + 针对以上情形,result 初始为 1(默认最右面有一个峰值),此时 curDiff> 0 && preDiff <= 0,那么 result++(计算了左面的峰值),最后得到的 result 就是 2(峰值个数为 2 即摆动序列长度为 2) @@ -147,7 +145,7 @@ public: 在版本一中,我们忽略了一种情况,即 如果在一个单调坡度上有平坡,例如[1,2,2,2,3,4],如图: - + 图中,我们可以看出,版本一的代码在三个地方记录峰值,但其实结果因为是 2,因为 单调中的平坡 不能算峰值(即摆动)。 @@ -186,7 +184,7 @@ public: **本题异常情况的本质,就是要考虑平坡**, 平坡分两种,一个是 上下中间有平坡,一个是单调有平坡,如图: - + ### 思路 2(动态规划) @@ -714,7 +712,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" "b/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" old mode 100644 new mode 100755 index ba8546c662..ab92f24aef --- "a/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" +++ "b/problems/0377.347円273円204円345円220円210円346円200円273円345円222円214円342円205円243円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 377. 组合总和 IV @@ -105,7 +103,7 @@ dp[i](考虑nums[j])可以由 dp[i - nums[j]](不考虑nums[j]) 推导 我们再来用示例中的例子推导一下: - + 如果代码运行处的结果不是想要的结果,就把dp[i]都打出来,看看和我们推导的一不一样。 @@ -357,7 +355,3 @@ public class Solution ``` -- - - diff --git "a/problems/0383.350円265円216円351円207円221円344円277円241円.md" "b/problems/0383.350円265円216円351円207円221円344円277円241円.md" old mode 100644 new mode 100755 index 1d7391732f..8a2f52ae42 --- "a/problems/0383.350円265円216円351円207円221円344円277円241円.md" +++ "b/problems/0383.350円265円216円351円207円221円344円277円241円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -466,8 +464,4 @@ bool canConstruct(char* ransomNote, char* magazine) { ``` -- - - diff --git "a/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md" "b/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index 92246e4f9b..bf2d959682 --- "a/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md" +++ "b/problems/0392.345円210円244円346円226円255円345円255円220円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 392.判断子序列 @@ -82,7 +80,7 @@ if (s[i - 1] != t[j - 1]),此时相当于t要删除元素,t如果把当前 因为这样的定义在dp二维矩阵中可以留出初始化的区间,如图: - + 如果要是定义的dp[i][j]是以下标i为结尾的字符串s和以下标j为结尾的字符串t,初始化就比较麻烦了。 @@ -100,14 +98,14 @@ vector- - - diff --git "a/problems/0404.345円267円246円345円217円266円345円255円220円344円271円213円345円222円214円.md" "b/problems/0404.345円267円246円345円217円266円345円255円220円344円271円213円345円222円214円.md" old mode 100644 new mode 100755 index 66aff68f2e..10b159b181 --- "a/problems/0404.345円267円246円345円217円266円345円255円220円344円271円213円345円222円214円.md" +++ "b/problems/0404.345円267円246円345円217円266円345円255円220円344円271円213円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 404.左叶子之和 @@ -14,7 +12,7 @@ 示例: - + ## 算法公开课 @@ -28,12 +26,12 @@ 大家思考一下如下图中二叉树,左叶子之和究竟是多少? - + **其实是0,因为这棵树根本没有左叶子!** 但看这个图的左叶子之和是多少? - + 相信通过这两个图,大家对最左叶子的定义有明确理解了。 @@ -685,7 +683,3 @@ public int SumOfLeftLeaves(TreeNode root) ``` -- - - diff --git "a/problems/0406.346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円.md" "b/problems/0406.346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円.md" old mode 100644 new mode 100755 index d6fc415b68..ce9d3bfb4e --- "a/problems/0406.346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円.md" +++ "b/problems/0406.346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 406.根据身高重建队列 @@ -63,7 +61,7 @@ 以图中{5,2} 为例: - + 按照身高排序之后,优先按身高高的people的k来插入,后序插入节点也不会影响前面已经插入的节点,最终按照k的规则完成了队列。 @@ -422,7 +420,3 @@ public class Solution -- - - diff --git "a/problems/0416.345円210円206円345円211円262円347円255円211円345円222円214円345円255円220円351円233円206円.md" "b/problems/0416.345円210円206円345円211円262円347円255円211円345円222円214円345円255円220円351円233円206円.md" old mode 100644 new mode 100755 index 902c022ab3..75bc5d0e10 --- "a/problems/0416.345円210円206円345円211円262円347円255円211円345円222円214円345円255円220円351円233円206円.md" +++ "b/problems/0416.345円210円206円345円211円262円347円255円211円345円222円214円345円255円220円351円233円206円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 416. 分割等和子集 @@ -157,7 +155,7 @@ dp[j]的数值一定是小于等于j的。 用例1,输入[1,5,11,5] 为例,如图: - + 最后dp[11] == 11,说明可以将这个数组分割成两个子集,使得两个子集的元素和相等。 @@ -801,7 +799,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0417.345円244円252円345円271円263円346円264円213円345円244円247円350円245円277円346円264円213円346円260円264円346円265円201円351円227円256円351円242円230円.md" "b/problems/0417.345円244円252円345円271円263円346円264円213円345円244円247円350円245円277円346円264円213円346円260円264円346円265円201円351円227円256円351円242円230円.md" old mode 100644 new mode 100755 index 5156ce2289..c9494313a1 --- "a/problems/0417.345円244円252円345円271円263円346円264円213円345円244円247円350円245円277円346円264円213円346円260円264円346円265円201円351円227円256円351円242円230円.md" +++ "b/problems/0417.345円244円252円345円271円263円346円264円213円345円244円247円350円245円277円346円264円213円346円260円264円346円265円201円351円227円256円351円242円230円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -20,7 +18,7 @@ 示例 1: - + * 输入: heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]] * 输出: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]] @@ -132,11 +130,11 @@ public: 从太平洋边上节点出发,如图: - + 从大西洋边上节点出发,如图: - + 按照这样的逻辑,就可以写出如下遍历代码:(详细注释) @@ -837,7 +835,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0435.346円227円240円351円207円215円345円217円240円345円214円272円351円227円264円.md" "b/problems/0435.346円227円240円351円207円215円345円217円240円345円214円272円351円227円264円.md" old mode 100644 new mode 100755 index d6321315d7..4231a8ee90 --- "a/problems/0435.346円227円240円351円207円215円345円217円240円345円214円272円351円227円264円.md" +++ "b/problems/0435.346円227円240円351円207円215円345円217円240円345円214円272円351円227円264円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 435. 无重叠区间 @@ -46,7 +44,7 @@ 这里记录非交叉区间的个数还是有技巧的,如图: - + 区间,1,2,3,4,5,6都按照右边界排好序。 @@ -495,7 +493,3 @@ public class Solution -- - - diff --git "a/problems/0450.345円210円240円351円231円244円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円350円212円202円347円202円271円.md" "b/problems/0450.345円210円240円351円231円244円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円350円212円202円347円202円271円.md" old mode 100644 new mode 100755 index 831655e8e1..44575b8aff --- "a/problems/0450.345円210円240円351円231円244円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円350円212円202円347円202円271円.md" +++ "b/problems/0450.345円210円240円351円231円244円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円350円212円202円347円202円271円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 二叉搜索树删除节点就涉及到结构调整了 @@ -22,7 +20,7 @@ 示例: - + ## 算法公开课 @@ -69,7 +67,7 @@ if (root == nullptr) return root; 第五种情况有点难以理解,看下面动画: - + 动画中的二叉搜索树中,删除元素7, 那么删除节点(元素7)的左孩子就是5,删除节点(元素7)的右子树的最左面节点是元素8。 @@ -836,7 +834,3 @@ def delete_node(root, key) end ``` -- - - diff --git "a/problems/0452.347円224円250円346円234円200円345円260円221円346円225円260円351円207円217円347円232円204円347円256円255円345円274円225円347円210円206円346円260円224円347円220円203円.md" "b/problems/0452.347円224円250円346円234円200円345円260円221円346円225円260円351円207円217円347円232円204円347円256円255円345円274円225円347円210円206円346円260円224円347円220円203円.md" old mode 100644 new mode 100755 index 14456f92bf..76de3f93a2 --- "a/problems/0452.347円224円250円346円234円200円345円260円221円346円225円260円351円207円217円347円232円204円347円256円255円345円274円225円347円210円206円346円260円224円347円220円203円.md" +++ "b/problems/0452.347円224円250円346円234円200円345円260円221円346円225円260円351円207円217円347円232円204円347円256円255円345円274円225円347円210円206円346円260円224円347円220円203円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 452. 用最少数量的箭引爆气球 @@ -78,7 +76,7 @@ 以题目示例: [[10,16],[2,8],[1,6],[7,12]]为例,如图:(方便起见,已经排序) - + 可以看出首先第一组重叠气球,一定是需要一个箭,气球3,的左边界大于了 第一组重叠气球的最小右边界,所以再需要一支箭来射气球3了。 @@ -357,7 +355,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0454.345円233円233円346円225円260円347円233円270円345円212円240円II.md" "b/problems/0454.345円233円233円346円225円260円347円233円270円345円212円240円II.md" old mode 100644 new mode 100755 index af19f5f7d8..76706e21dd --- "a/problems/0454.345円233円233円346円225円260円347円233円270円345円212円240円II.md" +++ "b/problems/0454.345円233円233円346円225円260円347円233円270円345円212円240円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 需要哈希的地方都能找到map的身影 @@ -62,18 +60,18 @@ C++代码: ```CPP class Solution { public: - int fourSumCount(vector- - - diff --git "a/problems/0455.345円210円206円345円217円221円351円245円274円345円271円262円.md" "b/problems/0455.345円210円206円345円217円221円351円245円274円345円271円262円.md" old mode 100644 new mode 100755 index 5e8fb73094..2c38ab9ec1 --- "a/problems/0455.345円210円206円345円217円221円351円245円274円345円271円262円.md" +++ "b/problems/0455.345円210円206円345円217円221円351円245円274円345円271円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 455.分发饼干 @@ -48,7 +46,7 @@ 如图: - + 这个例子可以看出饼干 9 只有喂给胃口为 7 的小孩,这样才是整体最优解,并想不出反例,那么就可以撸代码了。 @@ -91,7 +89,7 @@ public: 如果 for 控制的是饼干, if 控制胃口,就是出现如下情况 : - + if 里的 index 指向 胃口 10, for 里的 i 指向饼干 9,因为 饼干 9 满足不了 胃口 10,所以 i 持续向前移动,而 index 走不到` s[index]>= g[i]` 的逻辑,所以 index 不会移动,那么当 i 持续向前移动,最后所有的饼干都匹配不上。 @@ -434,7 +432,3 @@ public class Solution } ``` -- - - diff --git "a/problems/0459.351円207円215円345円244円215円347円232円204円345円255円220円345円255円227円347円254円246円344円270円262円.md" "b/problems/0459.351円207円215円345円244円215円347円232円204円345円255円220円345円255円227円347円254円246円344円270円262円.md" old mode 100644 new mode 100755 index 988b2abf11..d164277731 --- "a/problems/0459.351円207円215円345円244円215円347円232円204円345円255円220円345円255円227円347円254円246円344円270円262円.md" +++ "b/problems/0459.351円207円215円345円244円215円347円232円204円345円255円220円345円255円227円347円254円246円344円270円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > KMP算法还能干这个 @@ -48,13 +46,13 @@ 当一个字符串s:abcabc,内部由重复的子串组成,那么这个字符串的结构一定是这样的: - + 也就是由前后相同的子串组成。 那么既然前面有相同的子串,后面有相同的子串,用 s + s,这样组成的字符串中,后面的子串做前串,前面的子串做后串,就一定还能组成一个s,如图: - + 当然,我们在判断 s + s 拼接的字符串里是否出现一个s的的时候,**要刨除 s + s 的首字符和尾字符**,这样避免在s+s中搜索出原来的s,我们要搜索的是中间拼接出来的s。 @@ -66,11 +64,11 @@ 如图,字符串s,图中数字为数组下标,在 s + s 拼接后, 不算首尾字符,中间凑成s字符串。 (图中数字为数组下标) - + 图中,因为中间拼接成了s,根据红色框 可以知道 s[4] = s[0], s[5] = s[1], s[0] = s[2], s[1] = s[3] s[2] = s[4] ,s[3] = s[5] - + 以上相等关系我们串联一下: @@ -85,7 +83,7 @@ s[5] = s[1] = s[3] 这里可以有录友想,凭什么就是这样组成的s呢,我换一个方式组成s 行不行,如图: - + s[3] = s[0],s[4] = s[1] ,s[5] = s[2],s[0] = s[3],s[1] = s[4],s[2] = s[5] @@ -103,7 +101,7 @@ s[0] s[1] s[2] = s[3] s[4] s[5] 如果是这样的呢,如图: - + s[1] = s[0],s[2] = s[1] ,s[3] = s[2],s[4] = s[3],s[5] = s[4],s[0] = s[5] @@ -167,23 +165,23 @@ KMP算法中next数组为什么遇到字符不匹配的时候可以找到上一 那么相同前后缀可以是这样: - + 也可以是这样: - + 最长的相等前后缀,也就是这样: - + 这里有录友就想:如果字符串s 是由最小重复子串p组成,最长相等前后缀就不能更长一些? 例如这样: - + 如果这样的话,因为前后缀要相同,所以 p2 = p1,p3 = p2,如图: - + p2 = p1,p3 = p2 即: p1 = p2 = p3 @@ -205,7 +203,7 @@ p2 = p1,p3 = p2 即: p1 = p2 = p3 情况一, 最长相等前后缀不包含的子串的长度 比 字符串s的一半的长度还大,那一定不是字符串s的重复子串,如图: - + 图中:前后缀不包含的子串的长度 大于 字符串s的长度的 二分之一 @@ -213,7 +211,7 @@ p2 = p1,p3 = p2 即: p1 = p2 = p3 情况二,最长相等前后缀不包含的子串的长度 可以被 字符串s的长度整除,如图: - + 步骤一:因为 这是相等的前缀和后缀,t[0] 与 k[0]相同, t[1] 与 k[1]相同,所以 s[0] 一定和 s[2]相同,s[1] 一定和 s[3]相同,即:,s[0]s[1]与s[2]s[3]相同 。 @@ -236,7 +234,7 @@ p2 = p1,p3 = p2 即: p1 = p2 = p3 那么它的最长相同前后缀,就不是上图中的前后缀,而是这样的的前后缀: - + 录友可能再问,由一个字符组成的字符串,最长相等前后缀凭什么就是这样的。 @@ -252,7 +250,7 @@ p2 = p1,p3 = p2 即: p1 = p2 = p3 **情况三,最长相等前后缀不包含的子串的长度 不被 字符串s的长度整除得情况**,如图: - + 步骤一:因为 这是相等的前缀和后缀,t[0] 与 k[0]相同, t[1] 与 k[1]相同,t[2] 与 k[2]相同。 @@ -303,7 +301,7 @@ next 数组记录的就是最长相同前后缀( [字符串:KMP算法精讲] 如图: - + `next[len - 1] = 7`,`next[len - 1] + 1 = 8`,8就是此时字符串asdfasdfasdf的最长相同前后缀的长度。 @@ -999,7 +997,3 @@ bool repeatedSubstringPattern(char* s) { ``` -- - - diff --git "a/problems/0463.345円262円233円345円261円277円347円232円204円345円221円250円351円225円277円.md" "b/problems/0463.345円262円233円345円261円277円347円232円204円345円221円250円351円225円277円.md" old mode 100644 new mode 100755 index 5261d6c2ae..ba60bc4564 --- "a/problems/0463.345円262円233円345円261円277円347円232円204円345円221円250円351円225円277円.md" +++ "b/problems/0463.345円262円233円345円261円277円347円232円204円345円221円250円351円225円277円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -17,7 +15,7 @@ 岛屿中没有"湖"("湖" 指水域在岛屿内部且不和岛屿周围的水相连)。格子是边长为 1 的正方形。网格为长方形,且宽度和高度均不超过 100 。计算这个岛屿的周长。 - + * 输入:grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]] * 输出:16 @@ -51,7 +49,7 @@ 如图: - + C++代码如下:(详细注释) @@ -91,7 +89,7 @@ result = 岛屿数量 * 4 - cover * 2; 如图: - + C++代码如下:(详细注释) @@ -433,7 +431,3 @@ function islandPerimeter(grid: number[][]): number { ``` -- - - diff --git "a/problems/0474.344円270円200円345円222円214円351円233円266円.md" "b/problems/0474.344円270円200円345円222円214円351円233円266円.md" old mode 100644 new mode 100755 index 9d24f01434..750917de3e --- "a/problems/0474.344円270円200円345円222円214円351円233円266円.md" +++ "b/problems/0474.344円270円200円345円222円214円351円233円266円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 474.一和零 @@ -53,7 +51,7 @@ 其实本题并不是多重背包,再来看一下这个图,捋清几种背包的关系 - + 多重背包是每个物品,数量不同的情况。 @@ -129,7 +127,7 @@ for (string str : strs) { // 遍历物品 最后dp数组的状态如下所示: - + 以上动规五部曲分析完毕,C++代码如下: @@ -740,8 +738,4 @@ public class Solution ``` -- - - diff --git "a/problems/0491.351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円.md" "b/problems/0491.351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index 7832095a10..5d37737169 --- "a/problems/0491.351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円.md" +++ "b/problems/0491.351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 和子集问题有点像,但又处处是陷阱 @@ -47,7 +45,7 @@ 为了有鲜明的对比,我用[4, 7, 6, 7]这个数组来举例,抽象为树形结构如图: - + @@ -81,7 +79,7 @@ if (path.size()> 1) { * 单层搜索逻辑 - + 在图中可以看出,**同一父节点下的同层上使用过的元素就不能再使用了** 那么单层搜索代码如下: @@ -640,7 +638,3 @@ public class Solution { } ``` -- - - diff --git "a/problems/0494.347円233円256円346円240円207円345円222円214円.md" "b/problems/0494.347円233円256円346円240円207円345円222円214円.md" old mode 100644 new mode 100755 index c38ba7e43c..2e464394b4 --- "a/problems/0494.347円233円256円346円240円207円345円222円214円.md" +++ "b/problems/0494.347円233円256円346円240円207円345円222円214円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -165,7 +163,7 @@ if (abs(target)> sum) return 0; // 此时没有方案 先只考虑物品0,如图: - + (这里的所有物品,都是题目中的数字1)。 @@ -179,7 +177,7 @@ if (abs(target)> sum) return 0; // 此时没有方案 接下来 考虑 物品0 和 物品1,如图: - + 装满背包容量为0 的方法个数是1,即 放0件物品。 @@ -193,7 +191,7 @@ if (abs(target)> sum) return 0; // 此时没有方案 接下来 考虑 物品0 、物品1 和 物品2 ,如图: - + 装满背包容量为0 的方法个数是1,即 放0件物品。 @@ -209,17 +207,17 @@ if (abs(target)> sum) return 0; // 此时没有方案 如图红色部分: - + dp[2][2] = 3,即 放物品0 和 放物品1、放物品0 和 物品 2、放物品1 和 物品2, 如图所示,三种方法: - + **容量为2 的背包,如果不放 物品2 有几种方法呢**? 有 dp[1][2] 种方法,即 背包容量为2,只考虑物品0 和 物品1 ,有 dp[1][2] 种方法,如图: - + **容量为2 的背包, 如果放 物品2 有几种方法呢**? @@ -231,7 +229,7 @@ dp[2][2] = 3,即 放物品0 和 放物品1、放物品0 和 物品 2、放物 如图: - + 有录友可能疑惑,这里计算的是放满 容量为2的背包 有几种方法,那物品2去哪了? @@ -241,7 +239,7 @@ dp[2][2] = 容量为2的背包不放物品2有几种方法 + 容量为2的背包 所以 dp[2][2] = dp[1][2] + dp[1][1] ,如图: - + 以上过程,抽象化如下: @@ -268,11 +266,11 @@ else dp[i][j] = dp[i - 1][j] + dp[i - 1][j - nums[i]]; 先明确递推的方向,如图,求解 dp[2][2] 是由 上方和左上方推出。 - + 那么二维数组的最上行 和 最左列一定要初始化,这是递推公式推导的基础,如图红色部分: - + 关于dp[0][0]的值,在上面的递推公式讲解中已经讲过,装满背包容量为0 的方法数量是1,即 放0件物品。 @@ -325,7 +323,7 @@ for (int i = 0; i < nums.size(); i++) { 例如下图,如果上方没数值,左上方没数值,就无法推出 dp[2][2]。 - + 那么是先 从上到下 ,再从左到右遍历,例如这样: @@ -351,11 +349,11 @@ for (int j = 0; j <= bagSize; j++) { // 列,遍历背包 这里我再画图讲一下,以求dp[2][2]为例,当先从上到下,再从左到右遍历,矩阵是这样: - + 当先从左到右,再从上到下遍历,矩阵是这样: - + 这里大家可以看出,无论是以上哪种遍历,都不影响 dp[2][2]的求值,用来 推导 dp[2][2] 的数值都在。 @@ -368,7 +366,7 @@ bagSize = (target + sum) / 2 = (3 + 5) / 2 = 4 dp数组状态变化如下: - + 这么大的矩阵,我们是可以自己手动模拟出来的。 @@ -447,7 +445,7 @@ bagSize = (target + sum) / 2 = (3 + 5) / 2 = 4 dp数组状态变化如下: - + 大家可以和 二维dp数组的打印结果做一下对比。 @@ -686,7 +684,7 @@ class Solution: for i in range(1, len(nums)): for j in range(target_sum + 1): dp[i][j] = dp[i - 1][j] # 不选取当前元素 - if j>= nums[i - 1]: + if j>= nums[i]: #只有j>= 本次遍历元素才可以选取当前元素 dp[i][j] += dp[i - 1][j - nums[i]] # 选取当前元素 return dp[len(nums)-1][target_sum] # 返回达到目标和的方案数 @@ -1024,8 +1022,4 @@ public class Solution ``` -- - - diff --git "a/problems/0496.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円I.md" "b/problems/0496.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円I.md" old mode 100644 new mode 100755 index 02e73a588d..628149b75d --- "a/problems/0496.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円I.md" +++ "b/problems/0496.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円I.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 496.下一个更大元素 I @@ -507,7 +505,3 @@ impl Solution { -- - - diff --git "a/problems/0501.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円344円274円227円346円225円260円.md" "b/problems/0501.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円344円274円227円346円225円260円.md" old mode 100644 new mode 100755 index c89f8031e8..457fd61d24 --- "a/problems/0501.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円344円274円227円346円225円260円.md" +++ "b/problems/0501.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円344円274円227円346円225円260円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 二叉树上应该怎么求,二叉搜索树上又应该怎么求? @@ -25,7 +23,7 @@ 给定 BST [1,null,2,2], - + 返回[2]. @@ -146,7 +144,7 @@ public: 如图: - + 中序遍历代码如下: @@ -1052,7 +1050,3 @@ public class Solution -- - - diff --git "a/problems/0503.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円II.md" "b/problems/0503.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円II.md" old mode 100644 new mode 100755 index b466337d6e..93924483f3 --- "a/problems/0503.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円II.md" +++ "b/problems/0503.344円270円213円344円270円200円344円270円252円346円233円264円345円244円247円345円205円203円347円264円240円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 503.下一个更大元素II @@ -358,7 +356,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0509.346円226円220円346円263円242円351円202円243円345円245円221円346円225円260円.md" "b/problems/0509.346円226円220円346円263円242円351円202円243円345円245円221円346円225円260円.md" old mode 100644 new mode 100755 index ac173dbddc..b2e56a613c --- "a/problems/0509.346円226円220円346円263円242円351円202円243円345円245円221円346円225円260円.md" +++ "b/problems/0509.346円226円220円346円263円242円351円202円243円345円245円221円346円225円260円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 509. 斐波那契数 @@ -476,7 +474,3 @@ public class Solution -- - - diff --git "a/problems/0513.346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" "b/problems/0513.346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" old mode 100644 new mode 100755 index c7446726f8..03f076a2c9 --- "a/problems/0513.346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" +++ "b/problems/0513.346円211円276円346円240円221円345円267円246円344円270円213円350円247円222円347円232円204円345円200円274円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 513.找树左下角的值 @@ -14,11 +12,11 @@ 示例 1: - + 示例 2: - + ## 算法公开课 @@ -764,7 +762,3 @@ public class Solution // @lc code=end ``` -- - - diff --git "a/problems/0516.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円345円272円217円345円210円227円.md" "b/problems/0516.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index 166310aaff..882c36bb05 --- "a/problems/0516.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円345円272円217円345円210円227円.md" +++ "b/problems/0516.346円234円200円351円225円277円345円233円236円346円226円207円345円255円220円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -58,7 +56,7 @@ 如果s[i]与s[j]相同,那么dp[i][j] = dp[i + 1][j - 1] + 2; 如图: - + (如果这里看不懂,回忆一下dp[i][j]的定义) @@ -70,7 +68,7 @@ 那么dp[i][j]一定是取最大的,即:dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]); - + 代码如下: @@ -99,7 +97,7 @@ for (int i = 0; i < s.size(); i++) dp[i][i] = 1; 从递归公式中,可以看出,dp[i][j] 依赖于 dp[i + 1][j - 1] ,dp[i + 1][j] 和 dp[i][j - 1],如图: - + **所以遍历i的时候一定要从下到上遍历,这样才能保证下一行的数据是经过计算的**。 @@ -123,7 +121,7 @@ for (int i = s.size() - 1; i>= 0; i--) { 输入s:"cbbd" 为例,dp数组状态如图: - + 红色框即:dp[0][s.size() - 1]; 为最终结果。 @@ -299,7 +297,3 @@ impl Solution { -- - - diff --git "a/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" "b/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" old mode 100644 new mode 100755 index 835df85212..7e4bbb9a81 --- "a/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" +++ "b/problems/0518.351円233円266円351円222円261円345円205円221円346円215円242円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 518.零钱兑换II @@ -138,7 +136,7 @@ 那么二维数组的最上行 和 最左列一定要初始化,这是递推公式推导的基础,如图红色部分: - + 这里首先要关注的就是 dp[0][0] 应该是多少? @@ -298,7 +296,7 @@ for (int j = 0; j <= amount; j++) { // 遍历背包容量 输入: amount = 5, coins = [1, 2, 5] ,dp状态图如下: - + 最后红色框dp[amount]为最终结果。 @@ -589,7 +587,3 @@ public class Solution ``` -- - - diff --git "a/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" "b/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" old mode 100644 new mode 100755 index b6d08dbeaa..a8eca862ef --- "a/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" +++ "b/problems/0530.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円347円232円204円346円234円200円345円260円217円347円273円235円345円257円271円345円267円256円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 利用二叉搜索树的特性搞起! @@ -15,7 +13,7 @@ 示例: - + 提示:树中至少有 2 个节点。 @@ -72,7 +70,7 @@ public: 如图: - + 一些同学不知道在递归中如何记录前一个节点的指针,其实实现起来是很简单的,大家只要看过一次,写过一次,就掌握了。 @@ -679,8 +677,4 @@ public class Solution ``` -- - - diff --git "a/problems/0538.346円212円212円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円350円275円254円346円215円242円344円270円272円347円264円257円345円212円240円346円240円221円.md" "b/problems/0538.346円212円212円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円350円275円254円346円215円242円344円270円272円347円264円257円345円212円240円346円240円221円.md" old mode 100644 new mode 100755 index b95b585485..c4bfeae4b8 --- "a/problems/0538.346円212円212円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円350円275円254円346円215円242円344円270円272円347円264円257円345円212円240円346円240円221円.md" +++ "b/problems/0538.346円212円212円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円350円275円254円346円215円242円344円270円272円347円264円257円345円212円240円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 538.把二叉搜索树转换为累加树 @@ -20,7 +18,7 @@ 示例 1: - + * 输入:[4,1,6,0,2,5,7,null,null,null,3,null,null,null,8] * 输出:[30,36,21,36,35,26,15,null,null,null,33,null,null,null,8] @@ -69,7 +67,7 @@ 遍历顺序如图所示: - + 本题依然需要一个pre指针记录当前遍历节点cur的前一个节点,这样才方便做累加。 @@ -549,7 +547,3 @@ public class Solution -- - - diff --git "a/problems/0541.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円II.md" "b/problems/0541.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円II.md" old mode 100644 new mode 100755 index b3e7b02229..d5ad95c112 --- "a/problems/0541.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円II.md" +++ "b/problems/0541.345円217円215円350円275円254円345円255円227円347円254円246円344円270円262円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -40,7 +38,7 @@ **所以当需要固定规律一段一段去处理字符串的时候,要想想在for循环的表达式上做做文章。** 性能如下: - + 那么这里具体反转的逻辑我们要不要使用库函数呢,其实用不用都可以,使用reverse来实现反转也没毛病,毕竟不是解题关键部分。 @@ -516,8 +514,4 @@ impl Solution { } ``` -- - - diff --git "a/problems/0583.344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円347円232円204円345円210円240円351円231円244円346円223円215円344円275円234円.md" "b/problems/0583.344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円347円232円204円345円210円240円351円231円244円346円223円215円344円275円234円.md" old mode 100644 new mode 100755 index b9f9ad9625..8208d9a1eb --- "a/problems/0583.344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円347円232円204円345円210円240円351円231円244円346円223円215円344円275円234円.md" +++ "b/problems/0583.344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円347円232円204円345円210円240円351円231円244円346円223円215円344円275円234円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 583. 两个字符串的删除操作 @@ -83,7 +81,7 @@ for (int j = 0; j <= word2.size(); j++) dp[0][j] = j; 以word1:"sea",word2:"eat"为例,推导dp数组状态图如下: - + 以上分析完毕,代码如下: @@ -470,7 +468,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0617.345円220円210円345円271円266円344円272円214円345円217円211円346円240円221円.md" "b/problems/0617.345円220円210円345円271円266円344円272円214円345円217円211円346円240円221円.md" old mode 100644 new mode 100755 index 530350ac69..3ca5feb9da --- "a/problems/0617.345円220円210円345円271円266円344円272円214円345円217円211円346円240円221円.md" +++ "b/problems/0617.345円220円210円345円271円266円344円272円214円345円217円211円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 617.合并二叉树 @@ -15,7 +13,7 @@ 示例 1: - + 注意: 合并必须从两个树的根节点开始。 @@ -40,7 +38,7 @@ 动画如下: - + 那么我们来按照递归三部曲来解决: @@ -804,7 +802,3 @@ public TreeNode MergeTrees(TreeNode root1, TreeNode root2) ``` -- - - diff --git "a/problems/0647.345円233円236円346円226円207円345円255円220円344円270円262円.md" "b/problems/0647.345円233円236円346円226円207円345円255円220円344円270円262円.md" old mode 100644 new mode 100755 index cf32d7ed24..fd2ae43886 --- "a/problems/0647.345円233円236円346円226円207円345円255円220円344円270円262円.md" +++ "b/problems/0647.345円233円236円346円226円207円345円255円220円344円270円262円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 647. 回文子串 @@ -50,7 +48,7 @@ dp[i] 和 dp[i-1] ,dp[i + 1] 看上去都没啥关系。 所以我们要看回文串的性质。 如图: - + 我们在判断字符串S是否是回文,那么如果我们知道 s[1],s[2],s[3] 这个子串是回文的,那么只需要比较 s[0]和s[4]这两个元素是否相同,如果相同的话,这个字符串s 就是回文串。 @@ -108,7 +106,7 @@ dp[i][j]可以初始化为true么? 当然不行,怎能刚开始就全都匹 dp[i + 1][j - 1] 在 dp[i][j]的左下角,如图: - + 如果这矩阵是从上到下,从左到右遍历,那么会用到没有计算过的dp[i + 1][j - 1],也就是根据不确定是不是回文的区间[i+1,j-1],来判断了[i,j]是不是回文,那结果一定是不对的。 @@ -138,7 +136,7 @@ for (int i = s.size() - 1; i>= 0; i--) { // 注意遍历顺序 举例,输入:"aaa",dp[i][j]状态如下: - + 图中有6个true,所以就是有6个回文子串。 @@ -613,7 +611,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0649.Dota2345円217円202円350円256円256円351円231円242円.md" "b/problems/0649.Dota2345円217円202円350円256円256円351円231円242円.md" old mode 100644 new mode 100755 index 1540a60173..e77070fcf8 --- "a/problems/0649.Dota2345円217円202円350円256円256円351円231円242円.md" +++ "b/problems/0649.Dota2345円217円202円350円256円256円351円231円242円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -284,7 +282,3 @@ function predictPartyVictory(senate: string): string { -- - - diff --git "a/problems/0654.346円234円200円345円244円247円344円272円214円345円217円211円346円240円221円.md" "b/problems/0654.346円234円200円345円244円247円344円272円214円345円217円211円346円240円221円.md" old mode 100644 new mode 100755 index fed9b2b991..49ccc9cdea --- "a/problems/0654.346円234円200円345円244円247円344円272円214円345円217円211円346円240円221円.md" +++ "b/problems/0654.346円234円200円345円244円247円344円272円214円345円217円211円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 654.最大二叉树 @@ -19,7 +17,7 @@ 示例 : - + 提示: @@ -34,7 +32,7 @@ 最大二叉树的构建过程如下: - + 构造树一般采用的是前序遍历,因为先构造中间节点,然后递归构造左子树和右子树。 @@ -599,7 +597,3 @@ public TreeNode ConstructMaximumBinaryTree(int[] nums) ``` -- - - diff --git "a/problems/0657.346円234円272円345円231円250円344円272円272円350円203円275円345円220円246円350円277円224円345円233円236円345円216円237円347円202円271円.md" "b/problems/0657.346円234円272円345円231円250円344円272円272円350円203円275円345円220円246円350円277円224円345円233円236円345円216円237円347円202円271円.md" old mode 100644 new mode 100755 index eccfef3a21..c1706df4fa --- "a/problems/0657.346円234円272円345円231円250円344円272円272円350円203円275円345円220円246円350円277円224円345円233円236円345円216円237円347円202円271円.md" +++ "b/problems/0657.346円234円272円345円231円250円344円272円272円350円203円275円345円220円246円350円277円224円345円233円236円345円216円237円347円202円271円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 657. 机器人能否返回原点 @@ -42,7 +40,7 @@ 最后判断一下x,y是否回到了(0, 0)位置就可以了。 如图所示: - + C++代码如下: @@ -182,7 +180,3 @@ var judgeCircle = function (moves) { -- - - diff --git "a/problems/0669.344円277円256円345円211円252円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" "b/problems/0669.344円277円256円345円211円252円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" old mode 100644 new mode 100755 index 325733862c..dbcc6ed63d --- "a/problems/0669.344円277円256円345円211円252円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" +++ "b/problems/0669.344円277円256円345円211円252円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -16,9 +14,9 @@ 给定一个二叉搜索树,同时给定最小边界L 和最大边界 R。通过修剪二叉搜索树,使得所有节点的值在[L, R]中 (R>=L) 。你可能需要改变树的根节点,所以结果应当返回修剪好的二叉搜索树的新的根节点。 - + - + ## 算法公开课 @@ -52,7 +50,7 @@ public: 我们在重新关注一下第二个示例,如图: - + **所以以上的代码是不可行的!** @@ -62,7 +60,7 @@ public: 在上图中我们发现节点0并不符合区间要求,那么将节点0的右孩子 节点2 直接赋给 节点3的左孩子就可以了(就是把节点0从二叉树中移除),如图: - + 理解了最关键部分了我们再递归三部曲: @@ -129,7 +127,7 @@ return root; 在回顾一下上面的代码,针对下图中二叉树的情况: - + 如下代码相当于把节点0的右孩子(节点2)返回给上一层, @@ -587,7 +585,3 @@ public TreeNode TrimBST(TreeNode root, int low, int high) -- - - diff --git "a/problems/0673.346円234円200円351円225円277円351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円347円232円204円344円270円252円346円225円260円.md" "b/problems/0673.346円234円200円351円225円277円351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円347円232円204円344円270円252円346円225円260円.md" old mode 100644 new mode 100755 index 0366ee8063..9e61229abb --- "a/problems/0673.346円234円200円351円225円277円351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円347円232円204円344円270円252円346円225円260円.md" +++ "b/problems/0673.346円234円200円351円225円277円351円200円222円345円242円236円345円255円220円345円272円217円345円210円227円347円232円204円344円270円252円346円225円260円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 673.最长递增子序列的个数 @@ -180,7 +178,7 @@ for (int i = 0; i < nums.size(); i++) { 输入:[1,3,5,4,7] - + **如果代码写出来了,怎么改都通过不了,那么把dp和count打印出来看看对不对!** @@ -361,7 +359,3 @@ var findNumberOfLIS = function(nums) { -- - - diff --git "a/problems/0674.346円234円200円351円225円277円350円277円236円347円273円255円351円200円222円345円242円236円345円272円217円345円210円227円.md" "b/problems/0674.346円234円200円351円225円277円350円277円236円347円273円255円351円200円222円345円242円236円345円272円217円345円210円227円.md" old mode 100644 new mode 100755 index 8b967092bc..dae64a11ac --- "a/problems/0674.346円234円200円351円225円277円350円277円236円347円273円255円351円200円222円345円242円236円345円272円217円345円210円227円.md" +++ "b/problems/0674.346円234円200円351円225円277円350円277円236円347円273円255円351円200円222円345円242円236円345円272円217円345円210円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 674. 最长连续递增序列 @@ -87,7 +85,7 @@ for (int i = 1; i < nums.size(); i++) { 已输入nums = [1,3,5,4,7]为例,dp数组状态如下: - + **注意这里要取dp[i]里的最大值,所以dp[2]才是结果!** @@ -514,7 +512,3 @@ func findLengthOfLCIS(nums: Array- - - diff --git "a/problems/0684.345円206円227円344円275円231円350円277円236円346円216円245円.md" "b/problems/0684.345円206円227円344円275円231円350円277円236円346円216円245円.md" old mode 100644 new mode 100755 index 7808549036..2f939d0827 --- "a/problems/0684.345円206円227円344円275円231円350円277円236円346円216円245円.md" +++ "b/problems/0684.345円206円227円344円275円231円350円277円236円346円216円245円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 684.冗余连接 @@ -14,7 +12,7 @@ 请找出一条可以删去的边,删除后可使得剩余部分是一个有着 n 个节点的树。如果有多个答案,则返回数组 edges 中最后出现的边。 - + 提示: * n == edges.length @@ -87,7 +85,7 @@ void join(int u, int v) { 如图所示: - + 节点A 和节点 B 不在同一个集合,那么就可以将两个 节点连在一起。 @@ -97,7 +95,7 @@ void join(int u, int v) { 如图所示: - + 已经判断 节点A 和 节点B 在在同一个集合(同一个根),如果将 节点A 和 节点B 连在一起就一定会出现环。 @@ -379,7 +377,3 @@ var findRedundantConnection = function(edges) { -- - - diff --git "a/problems/0685.345円206円227円344円275円231円350円277円236円346円216円245円II.md" "b/problems/0685.345円206円227円344円275円231円350円277円236円346円216円245円II.md" old mode 100644 new mode 100755 index 3f489d82b7..27161d174c --- "a/problems/0685.345円206円227円344円275円231円350円277円236円346円216円245円II.md" +++ "b/problems/0685.345円206円227円344円275円231円350円277円236円346円216円245円II.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 685.冗余连接II @@ -18,9 +16,9 @@ 返回一条能删除的边,使得剩下的图是有 n 个节点的有根树。若有多个答案,返回最后出现在给定二维数组的答案。 - + - + 提示: @@ -40,7 +38,7 @@ 那么有如下三种情况,前两种情况是出现入度为2的点,如图: - + 且只有一个节点入度为2,为什么不看出度呢,出度没有意义,一棵树中随便一个父节点就有多个出度。 @@ -48,7 +46,7 @@ 如图: - + 首先先计算节点的入度,这里不少录友在计算入度的时候就搞蒙了,分不清 edges[i][j] 表示的都是什么。 @@ -620,7 +618,3 @@ var findRedundantDirectedConnection = function(edges) { -- - - diff --git "a/problems/0695.345円262円233円345円261円277円347円232円204円346円234円200円345円244円247円351円235円242円347円247円257円.md" "b/problems/0695.345円262円233円345円261円277円347円232円204円346円234円200円345円244円247円351円235円242円347円247円257円.md" old mode 100644 new mode 100755 index ca70420687..a63d2b0e06 --- "a/problems/0695.345円262円233円345円261円277円347円232円204円346円234円200円345円244円247円351円235円242円347円247円257円.md" +++ "b/problems/0695.345円262円233円345円261円277円347円232円204円346円234円200円345円244円247円351円235円242円347円247円257円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 695. 岛屿的最大面积 @@ -16,7 +14,7 @@ 计算并返回 grid 中最大的岛屿面积。如果没有岛屿,则返回面积为 0 。 - + * 输入:grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]] * 输出:6 @@ -29,7 +27,7 @@ 也就是说斜角度链接是不算了, 例如示例二,是三个岛屿,如图: - + 这道题目也是 dfs bfs基础类题目,就是搜索每个岛屿上"1"的数量,然后取一个最大的。 @@ -709,7 +707,3 @@ impl Solution { } ``` -- - - diff --git "a/problems/0700.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円220円234円347円264円242円.md" "b/problems/0700.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円220円234円347円264円242円.md" old mode 100644 new mode 100755 index 9ec51524b8..40777a67a2 --- "a/problems/0700.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円220円234円347円264円242円.md" +++ "b/problems/0700.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円220円234円347円264円242円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 700.二叉搜索树中的搜索 @@ -14,7 +12,7 @@ 例如, - + 在上述示例中,如果要找的值是 5,但因为没有节点值为 5,我们应该返回 NULL。 @@ -126,7 +124,7 @@ public: 中间节点如果大于3就向左走,如果小于3就向右走,如图: - + 所以迭代法代码如下: @@ -508,7 +506,3 @@ public TreeNode SearchBST(TreeNode root, int val) ``` -- - - diff --git "a/problems/0701.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円217円222円345円205円245円346円223円215円344円275円234円.md" "b/problems/0701.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円217円222円345円205円245円346円223円215円344円275円234円.md" old mode 100644 new mode 100755 index 25d39486f3..fec287449c --- "a/problems/0701.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円217円222円345円205円245円346円223円215円344円275円234円.md" +++ "b/problems/0701.344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円344円270円255円347円232円204円346円217円222円345円205円245円346円223円215円344円275円234円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 701.二叉搜索树中的插入操作 @@ -14,7 +12,7 @@ 注意,可能存在多种有效的插入方式,只要树在插入后仍保持为二叉搜索树即可。 你可以返回任意有效的结果。 - + 提示: @@ -35,7 +33,7 @@ 如下演示视频中可以看出:只要按照二叉搜索树的规则去遍历,遇到空节点就插入节点就可以了。 - + 例如插入元素10 ,需要找到末尾节点插入便可,一样的道理来插入元素15,插入元素0,插入元素6,**需要调整二叉树的结构么? 并不需要。**。 @@ -724,7 +722,3 @@ public TreeNode InsertIntoBST(TreeNode root, int val) { ``` -- - - diff --git "a/problems/0704.344円272円214円345円210円206円346円237円245円346円211円276円.md" "b/problems/0704.344円272円214円345円210円206円346円237円245円346円211円276円.md" old mode 100644 new mode 100755 index d86146d63a..e529629492 --- "a/problems/0704.344円272円214円345円210円206円346円237円245円346円211円276円.md" +++ "b/problems/0704.344円272円214円345円210円206円346円237円245円346円211円276円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 704. 二分查找 @@ -61,7 +59,7 @@ 例如在数组:1,2,3,4,7,9,10中查找元素2,如图所示: - + 代码如下:(详细注释) @@ -104,7 +102,7 @@ public: 在数组:1,2,3,4,7,9,10中查找元素2,如图所示:(**注意和方法一的区别**) - + 代码如下:(详细注释) @@ -837,7 +835,3 @@ class Solution { ``` -- - - diff --git "a/problems/0707.350円256円276円350円256円241円351円223円276円350円241円250円.md" "b/problems/0707.350円256円276円350円256円241円351円223円276円350円241円250円.md" old mode 100644 new mode 100755 index 5c72b05a29..72e35f430f --- "a/problems/0707.350円256円276円350円256円241円351円223円276円350円241円250円.md" +++ "b/problems/0707.350円256円276円350円256円241円351円223円276円350円241円250円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) > 听说这道题目把链表常见的五个操作都覆盖了? @@ -22,7 +20,7 @@ * deleteAtIndex(index):如果索引 index 有效,则删除链表中的第 index 个节点。 - + ## 算法公开课 @@ -37,10 +35,10 @@ 如果对链表的虚拟头结点不清楚,可以看这篇文章:[链表:听说用虚拟头节点会方便很多?](https://programmercarl.com/0203.移除链表元素.html) 删除链表节点: - + 添加链表节点: - + 这道题目设计链表的五个接口: * 获取链表第index个节点的数值 @@ -1845,8 +1843,4 @@ public class MyLinkedList } ``` -- - - diff --git "a/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円.md" "b/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円.md" old mode 100644 new mode 100755 index e742b8c89b..fb095d7518 --- "a/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円.md" +++ "b/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 714. 买卖股票的最佳时机含手续费 @@ -361,7 +359,3 @@ object Solution { ``` -- - - diff --git "a/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" "b/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" old mode 100644 new mode 100755 index 17997b6208..ebed4a0b30 --- "a/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" +++ "b/problems/0714.344円271円260円345円215円226円350円202円241円347円245円250円347円232円204円346円234円200円344円275円263円346円227円266円346円234円272円345円220円253円346円211円213円347円273円255円350円264円271円357円274円210円345円212円250円346円200円201円350円247円204円345円210円222円357円274円211円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 714.买卖股票的最佳时机含手续费 @@ -337,7 +335,3 @@ impl Solution { ``` -- - - diff --git "a/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" "b/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" old mode 100644 new mode 100755 index 1391926a76..12384a57a7 --- "a/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" +++ "b/problems/0718.346円234円200円351円225円277円351円207円215円345円244円215円345円255円220円346円225円260円347円273円204円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 718. 最长重复子数组 @@ -97,7 +95,7 @@ for (int i = 1; i <= nums1.size(); i++) { 拿示例1中,A: [1,2,3,2,1],B: [3,2,1,4,7]为例,画一个dp数组的状态变化,如下: - + 以上五部曲分析完毕,C++代码如下: @@ -129,7 +127,7 @@ public: 在如下图中: - + 我们可以看出dp[i][j]都是由dp[i - 1][j - 1]推出。那么压缩为一维数组,也就是dp[j]都是由dp[j - 1]推出。 @@ -602,7 +600,3 @@ func findLength(nums1: Array- - - diff --git "a/problems/0724.345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円347円264円242円345円274円225円.md" "b/problems/0724.345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円347円264円242円345円274円225円.md" old mode 100644 new mode 100755 index a66a445083..bccca4f2d4 --- "a/problems/0724.345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円347円264円242円345円274円225円.md" +++ "b/problems/0724.345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円347円264円242円345円274円225円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 724.寻找数组的中心下标 @@ -159,7 +157,3 @@ function pivotIndex(nums: number[]): number { -- - - diff --git "a/problems/0738.345円215円225円350円260円203円351円200円222円345円242円236円347円232円204円346円225円260円345円255円227円.md" "b/problems/0738.345円215円225円350円260円203円351円200円222円345円242円236円347円232円204円346円225円260円345円255円227円.md" old mode 100644 new mode 100755 index f2cfee04c9..17182778ae --- "a/problems/0738.345円215円225円350円260円203円351円200円222円345円242円236円347円232円204円346円225円260円345円255円227円.md" +++ "b/problems/0738.345円215円225円350円260円203円351円200円222円345円242円236円347円232円204円346円225円260円345円255円227円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) # 738.单调递增的数字 @@ -441,8 +439,4 @@ public class Solution } ``` -- - - diff --git "a/problems/0739.346円257円217円346円227円245円346円270円251円345円272円246円.md" "b/problems/0739.346円257円217円346円227円245円346円270円251円345円272円246円.md" old mode 100644 new mode 100755 index dd633aed9a..2ad7e6b79b --- "a/problems/0739.346円257円217円346円227円245円346円270円251円345円272円246円.md" +++ "b/problems/0739.346円257円217円346円227円245円346円270円251円345円272円246円.md" @@ -1,8 +1,6 @@ -
- - - -
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html) +* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html) +* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html) @@ -71,7 +69,7 @@ 首先先将第一个遍历元素加入单调栈 - + --------- @@ -79,65 +77,65 @@ 我们要保持一个递增单调栈(从栈头到栈底),所以将T[0]弹出,T[1]加入,此时result数组可以记录了,result[0] = 1,即T[0]右面第一个比T[0]大的元素是T[1]。 - + ----------- 加入T[2],同理,T[1]弹出 - + ------- 加入T[3],T[3] < T[2] (当前遍历的元素T[i]小于栈顶元素T[st.top()]的情况),加T[3]加入单调栈。 - + --------- 加入T[4],T[4] == T[3] (当前遍历的元素T[i]等于栈顶元素T[st.top()]的情况),此时依然要加入栈,不用计算距离,因为我们要求的是右面第一个大于本元素的位置,而不是大于等于! - + --------- 加入T[5],T[5]> T[4] (当前遍历的元素T[i]大于栈顶元素T[st.top()]的情况),将T[4]弹出,同时计算距离,更新result - + ---------- T[4]弹出之后, T[5]> T[3] (当前遍历的元素T[i]大于栈顶元素T[st.top()]的情况),将T[3]继续弹出,同时计算距离,更新result - + ------- 直到发现T[5]小于T[st.top()],终止弹出,将T[5]加入单调栈 - + ------- 加入T[6],同理,需要将栈里的T[5],T[2]弹出 - + ------- 同理,继续弹出 - + ------ 此时栈里只剩下了T[6] - + ------------ 加入T[7], T[7] < T[6] 直接入栈,这就是最后的情况,result数组也更新完了。 - + 此时有同学可能就疑惑了,那result[6] , result[7]怎么没更新啊,元素也一直在栈里。 @@ -515,7 +513,3 @@ impl Solution { -
-
-
-
diff --git "a/problems/0743.347円275円221円347円273円234円345円273円266円350円277円237円346円227円266円351円227円264円.md" "b/problems/0743.347円275円221円347円273円234円345円273円266円350円277円237円346円227円266円351円227円264円.md"
index e631951a9e..40b699c18f 100644
--- "a/problems/0743.347円275円221円347円273円234円345円273円266円350円277円237円346円227円266円351円227円264円.md"
+++ "b/problems/0743.347円275円221円347円273円234円345円273円266円350円277円237円346円227円266円351円227円264円.md"
@@ -1,3 +1,6 @@
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html)
+* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html)
+* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html)
# 743.网络延迟时间
@@ -10,7 +13,7 @@ https://leetcode.cn/problems/network-delay-time/description/
现在,从某个节点 K 发出一个信号。需要多久才能使所有节点都收到信号?如果不能使所有节点收到信号,返回 -1 。
-
+
提示:
@@ -39,7 +42,7 @@ dijkstra算法:在有权图(权值非负数)中求从起点到其他节点
如本题示例中的图:
-
+
起点(节点1)到终点(节点7) 的最短路径是 图中 标记绿线的部分。
@@ -85,7 +88,7 @@ minDist数组数值初始化为int最大值。
这里在强点一下 **minDist数组的含义:记录所有节点到源点的最短路径**,那么初始化的时候就应该初始为最大值,这样才能在后续出现最短路径的时候及时更新。
-
+
(图中,max 表示默认值,节点0 不做处理,统一从下标1 开始计算,这样下标和节点数值统一, 方便大家理解,避免搞混)
@@ -107,7 +110,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
更新 minDist数组,即:源点(节点1) 到 节点2 和 节点3的距离。
@@ -133,7 +136,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
更新 minDist数组,即:源点(节点1) 到 节点6 、 节点3 和 节点4的距离。
@@ -167,7 +170,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点3的加入,那么源点可以有新的路径链接到节点4 所以更新minDist数组:
@@ -187,7 +190,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点4的加入,那么源点可以链接到节点5 所以更新minDist数组:
@@ -207,7 +210,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点6的加入,那么源点可以链接到节点7 所以 更新minDist数组:
@@ -227,7 +230,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点5的加入,那么源点有新的路径可以链接到节点7 所以 更新minDist数组:
@@ -245,7 +248,7 @@ minDist数组数值初始化为int最大值。
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
节点7加入,但节点7到节点7的距离为0,所以 不用更新minDist数组
@@ -259,7 +262,7 @@ minDist数组数值初始化为int最大值。
路径如图:
-
+
在上面的讲解中,每一步 我都是按照 dijkstra 三部曲来讲解的,理解了这三部曲,代码也就好懂的。
@@ -428,7 +431,7 @@ select:4
看一下这个图: (有负权值)
-
+
节点1 到 节点5 的最短路径 应该是 节点1 -> 节点2 -> 节点3 -> 节点4 -> 节点5
@@ -438,7 +441,7 @@ select:4
初始化:
-
+
---------------
@@ -452,7 +455,7 @@ select:4
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
更新 minDist数组,即:源点(节点1) 到 节点2 和 节点3的距离。
@@ -471,7 +474,7 @@ select:4
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点3的加入,那么源点可以有新的路径链接到节点4 所以更新minDist数组:
@@ -489,7 +492,7 @@ select:4
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点4的加入,那么源点可以有新的路径链接到节点5 所以更新minDist数组:
@@ -507,7 +510,7 @@ select:4
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
节点5的加入,而节点5 没有链接其他节点, 所以不用更新minDist数组,仅标记节点5被访问过了
@@ -523,7 +526,7 @@ select:4
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
--------------
@@ -651,7 +654,7 @@ for (int v = 1; v <= n; v++) { 如图: - + 在一个 n (节点数)为8 的图中,就需要申请 8 * 8 这么大的空间,有一条双向边,即:grid[2][5] = 6,grid[5][2] = 6 @@ -675,7 +678,7 @@ for (int v = 1; v <= n; v++) { 邻接表的构造如图: - + 这里表达的图是: @@ -760,7 +763,7 @@ vector
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0763.345円210円222円345円210円206円345円255円227円346円257円215円345円214円272円351円227円264円.md" "b/problems/0763.345円210円222円345円210円206円345円255円227円346円257円215円345円214円272円351円227円264円.md"
old mode 100644
new mode 100755
index 19d862db14..d17878381f
--- "a/problems/0763.345円210円222円345円210円206円345円255円227円346円257円215円345円214円272円351円227円264円.md"
+++ "b/problems/0763.345円210円222円345円210円206円345円255円227円346円257円215円345円214円272円351円227円264円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0787.K347円253円231円344円270円255円350円275円254円345円206円205円346円234円200円344円276円277円345円256円234円347円232円204円350円210円252円347円217円255円.md" "b/problems/0787.K347円253円231円344円270円255円350円275円254円345円206円205円346円234円200円344円276円277円345円256円234円347円232円204円350円210円252円347円217円255円.md"
index 9c0a8e7f27..fb58c14816 100644
--- "a/problems/0787.K347円253円231円344円270円255円350円275円254円345円206円205円346円234円200円344円276円277円345円256円234円347円232円204円350円210円252円347円217円255円.md"
+++ "b/problems/0787.K347円253円231円344円270円255円350円275円254円345円206円205円346円234円200円344円276円277円345円256円234円347円232円204円350円210円252円347円217円255円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0797.346円211円200円346円234円211円345円217円257円350円203円275円347円232円204円350円267円257円345円276円204円.md" "b/problems/0797.346円211円200円346円234円211円345円217円257円350円203円275円347円232円204円350円267円257円345円276円204円.md"
old mode 100644
new mode 100755
index 40e1bbe73e..db4d249a15
--- "a/problems/0797.346円211円200円346円234円211円345円217円257円350円203円275円347円232円204円350円267円257円345円276円204円.md"
+++ "b/problems/0797.346円211円200円346円234円211円345円217円257円350円203円275円347円232円204円350円267円257円345円276円204円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0827.346円234円200円345円244円247円344円272円272円345円267円245円345円262円233円.md" "b/problems/0827.346円234円200円345円244円247円344円272円272円345円267円245円345円262円233円.md"
old mode 100644
new mode 100755
index d24eaacc50..118735e943
--- "a/problems/0827.346円234円200円345円244円247円344円272円272円345円267円245円345円262円233円.md"
+++ "b/problems/0827.346円234円200円345円244円247円344円272円272円345円267円245円345円262円233円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0841.351円222円245円345円214円231円345円222円214円346円210円277円351円227円264円.md" "b/problems/0841.351円222円245円345円214円231円345円222円214円346円210円277円351円227円264円.md"
old mode 100644
new mode 100755
index b78693b446..ffcf2fb919
--- "a/problems/0841.351円222円245円345円214円231円345円222円214円346円210円277円351円227円264円.md"
+++ "b/problems/0841.351円222円245円345円214円231円345円222円214円346円210円277円351円227円264円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0844.346円257円224円350円276円203円345円220円253円351円200円200円346円240円274円347円232円204円345円255円227円347円254円246円344円270円262円.md" "b/problems/0844.346円257円224円350円276円203円345円220円253円351円200円200円346円240円274円347円232円204円345円255円227円347円254円246円344円270円262円.md"
old mode 100644
new mode 100755
index c32cdd339b..6d0cd68578
--- "a/problems/0844.346円257円224円350円276円203円345円220円253円351円200円200円346円240円274円347円232円204円345円255円227円347円254円246円344円270円262円.md"
+++ "b/problems/0844.346円257円224円350円276円203円345円220円253円351円200円200円346円240円274円347円232円204円345円255円227円347円254円246円344円270円262円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0860.346円237円240円346円252円254円346円260円264円346円211円276円351円233円266円.md" "b/problems/0860.346円237円240円346円252円254円346円260円264円346円211円276円351円233円266円.md"
old mode 100644
new mode 100755
index b7887d456e..aeb470fe5a
--- "a/problems/0860.346円237円240円346円252円254円346円260円264円346円211円276円351円233円266円.md"
+++ "b/problems/0860.346円237円240円346円252円254円346円260円264円346円211円276円351円233円266円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0922.346円214円211円345円245円207円345円201円266円346円216円222円345円272円217円346円225円260円347円273円204円II.md" "b/problems/0922.346円214円211円345円245円207円345円201円266円346円216円222円345円272円217円346円225円260円347円273円204円II.md"
old mode 100644
new mode 100755
index 28680dbf0f..484099f89f
--- "a/problems/0922.346円214円211円345円245円207円345円201円266円346円216円222円345円272円217円346円225円260円347円273円204円II.md"
+++ "b/problems/0922.346円214円211円345円245円207円345円201円266円346円216円222円345円272円217円346円225円260円347円273円204円II.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0925.351円225円277円346円214円211円351円224円256円345円205円245円.md" "b/problems/0925.351円225円277円346円214円211円351円224円256円345円205円245円.md"
old mode 100644
new mode 100755
index f4a8fa8e52..f653caef52
--- "a/problems/0925.351円225円277円346円214円211円351円224円256円345円205円245円.md"
+++ "b/problems/0925.351円225円277円346円214円211円351円224円256円345円205円245円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0941.346円234円211円346円225円210円347円232円204円345円261円261円350円204円211円346円225円260円347円273円204円.md" "b/problems/0941.346円234円211円346円225円210円347円232円204円345円261円261円350円204円211円346円225円260円347円273円204円.md"
old mode 100644
new mode 100755
index 77167df041..9f000e2bb5
--- "a/problems/0941.346円234円211円346円225円210円347円232円204円345円261円261円350円204円211円346円225円260円347円273円204円.md"
+++ "b/problems/0941.346円234円211円346円225円210円347円232円204円345円261円261円350円204円211円346円225円260円347円273円204円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0968.347円233円221円346円216円247円344円272円214円345円217円211円346円240円221円.md" "b/problems/0968.347円233円221円346円216円247円344円272円214円345円217円211円346円240円221円.md"
old mode 100644
new mode 100755
index 327c54f72a..989993acf5
--- "a/problems/0968.347円233円221円346円216円247円344円272円214円345円217円211円346円240円221円.md"
+++ "b/problems/0968.347円233円221円346円216円247円344円272円214円345円217円211円346円240円221円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/0977.346円234円211円345円272円217円346円225円260円347円273円204円347円232円204円345円271円263円346円226円271円.md" "b/problems/0977.346円234円211円345円272円217円346円225円260円347円273円204円347円232円204円345円271円263円346円226円271円.md"
old mode 100644
new mode 100755
index b8488e10de..1f58fd5198
--- "a/problems/0977.346円234円211円345円272円217円346円225円260円347円273円204円347円232円204円345円271円263円346円226円271円.md"
+++ "b/problems/0977.346円234円211円345円272円217円346円225円260円347円273円204円347円232円204円345円271円263円346円226円271円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1002.346円237円245円346円211円276円345円270円270円347円224円250円345円255円227円347円254円246円.md" "b/problems/1002.346円237円245円346円211円276円345円270円270円347円224円250円345円255円227円347円254円246円.md"
old mode 100644
new mode 100755
index f938c2b734..cbf5ecdb78
--- "a/problems/1002.346円237円245円346円211円276円345円270円270円347円224円250円345円255円227円347円254円246円.md"
+++ "b/problems/1002.346円237円245円346円211円276円345円270円270円347円224円250円345円255円227円347円254円246円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1005.K346円254円241円345円217円226円345円217円215円345円220円216円346円234円200円345円244円247円345円214円226円347円232円204円346円225円260円347円273円204円345円222円214円.md" "b/problems/1005.K346円254円241円345円217円226円345円217円215円345円220円216円346円234円200円345円244円247円345円214円226円347円232円204円346円225円260円347円273円204円345円222円214円.md"
old mode 100644
new mode 100755
index 1a7817775a..6e908d5af6
--- "a/problems/1005.K346円254円241円345円217円226円345円217円215円345円220円216円346円234円200円345円244円247円345円214円226円347円232円204円346円225円260円347円273円204円345円222円214円.md"
+++ "b/problems/1005.K346円254円241円345円217円226円345円217円215円345円220円216円346円234円200円345円244円247円345円214円226円347円232円204円346円225円260円347円273円204円345円222円214円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1020.351円243円236円345円234円260円347円232円204円346円225円260円351円207円217円.md" "b/problems/1020.351円243円236円345円234円260円347円232円204円346円225円260円351円207円217円.md"
old mode 100644
new mode 100755
index f708e4a368..396e6c566b
--- "a/problems/1020.351円243円236円345円234円260円347円232円204円346円225円260円351円207円217円.md"
+++ "b/problems/1020.351円243円236円345円234円260円347円232円204円346円225円260円351円207円217円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md" "b/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md"
old mode 100644
new mode 100755
index 5164e1f7ff..16bf869ea6
--- "a/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md"
+++ "b/problems/1035.344円270円215円347円233円270円344円272円244円347円232円204円347円272円277円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1047.345円210円240円351円231円244円345円255円227円347円254円246円344円270円262円344円270円255円347円232円204円346円211円200円346円234円211円347円233円270円351円202円273円351円207円215円345円244円215円351円241円271円.md" "b/problems/1047.345円210円240円351円231円244円345円255円227円347円254円246円344円270円262円344円270円255円347円232円204円346円211円200円346円234円211円347円233円270円351円202円273円351円207円215円345円244円215円351円241円271円.md"
old mode 100644
new mode 100755
index 51ec4e62c6..36702194be
--- "a/problems/1047.345円210円240円351円231円244円345円255円227円347円254円246円344円270円262円344円270円255円347円232円204円346円211円200円346円234円211円347円233円270円351円202円273円351円207円215円345円244円215円351円241円271円.md"
+++ "b/problems/1047.345円210円240円351円231円244円345円255円227円347円254円246円344円270円262円344円270円255円347円232円204円346円211円200円346円234円211円347円233円270円351円202円273円351円207円215円345円244円215円351円241円271円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1049.346円234円200円345円220円216円344円270円200円345円235円227円347円237円263円345円244円264円347円232円204円351円207円215円351円207円217円II.md" "b/problems/1049.346円234円200円345円220円216円344円270円200円345円235円227円347円237円263円345円244円264円347円232円204円351円207円215円351円207円217円II.md"
old mode 100644
new mode 100755
index 0d445a71f0..ddc9f313db
--- "a/problems/1049.346円234円200円345円220円216円344円270円200円345円235円227円347円237円263円345円244円264円347円232円204円351円207円215円351円207円217円II.md"
+++ "b/problems/1049.346円234円200円345円220円216円344円270円200円345円235円227円347円237円263円345円244円264円347円232円204円351円207円215円351円207円217円II.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md" "b/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md"
old mode 100644
new mode 100755
index 6d05ccf3f8..424f403938
--- "a/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md"
+++ "b/problems/1143.346円234円200円351円225円277円345円205円254円345円205円261円345円255円220円345円272円217円345円210円227円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md" "b/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md"
old mode 100644
new mode 100755
index 781badf549..72462f1119
--- "a/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md"
+++ "b/problems/1207.347円213円254円344円270円200円346円227円240円344円272円214円347円232円204円345円207円272円347円216円260円346円254円241円346円225円260円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1221.345円210円206円345円211円262円345円271円263円350円241円241円345円255円227円347円254円246円344円270円262円.md" "b/problems/1221.345円210円206円345円211円262円345円271円263円350円241円241円345円255円227円347円254円246円344円270円262円.md"
old mode 100644
new mode 100755
index a32ca98ffc..a9e275d92d
--- "a/problems/1221.345円210円206円345円211円262円345円271円263円350円241円241円345円255円227円347円254円246円344円270円262円.md"
+++ "b/problems/1221.345円210円206円345円211円262円345円271円263円350円241円241円345円255円227円347円254円246円344円270円262円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1254.347円273円237円350円256円241円345円260円201円351円227円255円345円262円233円345円261円277円347円232円204円346円225円260円347円233円256円.md" "b/problems/1254.347円273円237円350円256円241円345円260円201円351円227円255円345円262円233円345円261円277円347円232円204円346円225円260円347円233円256円.md"
old mode 100644
new mode 100755
index 3d7b9fe96c..b440c32648
--- "a/problems/1254.347円273円237円350円256円241円345円260円201円351円227円255円345円262円233円345円261円277円347円232円204円346円225円260円347円233円256円.md"
+++ "b/problems/1254.347円273円237円350円256円241円345円260円201円351円227円255円345円262円233円345円261円277円347円232円204円346円225円260円347円233円256円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1334.351円230円210円345円200円274円350円267円235円347円246円273円345円206円205円351円202円273円345円261円205円346円234円200円345円260円221円347円232円204円345円237円216円345円270円202円.md" "b/problems/1334.351円230円210円345円200円274円350円267円235円347円246円273円345円206円205円351円202円273円345円261円205円346円234円200円345円260円221円347円232円204円345円237円216円345円270円202円.md"
index d8d8861f47..bea47a2e63 100644
--- "a/problems/1334.351円230円210円345円200円274円350円267円235円347円246円273円345円206円205円351円202円273円345円261円205円346円234円200円345円260円221円347円232円204円345円237円216円345円270円202円.md"
+++ "b/problems/1334.351円230円210円345円200円274円350円267円235円347円246円273円345円206円205円351円202円273円345円261円205円346円234円200円345円260円221円347円232円204円345円237円216円345円270円202円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1356.346円240円271円346円215円256円346円225円260円345円255円227円344円272円214円350円277円233円345円210円266円344円270円2131円347円232円204円346円225円260円347円233円256円346円216円222円345円272円217円.md" "b/problems/1356.346円240円271円346円215円256円346円225円260円345円255円227円344円272円214円350円277円233円345円210円266円344円270円2131円347円232円204円346円225円260円347円233円256円346円216円222円345円272円217円.md"
old mode 100644
new mode 100755
index 9cfb674328..11f947a184
--- "a/problems/1356.346円240円271円346円215円256円346円225円260円345円255円227円344円272円214円350円277円233円345円210円266円344円270円2131円347円232円204円346円225円260円347円233円256円346円216円222円345円272円217円.md"
+++ "b/problems/1356.346円240円271円346円215円256円346円225円260円345円255円227円344円272円214円350円277円233円345円210円266円344円270円2131円347円232円204円346円225円260円347円233円256円346円216円222円345円272円217円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1365.346円234円211円345円244円232円345円260円221円345円260円217円344円272円216円345円275円223円345円211円215円346円225円260円345円255円227円347円232円204円346円225円260円345円255円227円.md" "b/problems/1365.346円234円211円345円244円232円345円260円221円345円260円217円344円272円216円345円275円223円345円211円215円346円225円260円345円255円227円347円232円204円346円225円260円345円255円227円.md"
old mode 100644
new mode 100755
index f0a77f5587..61b548abf8
--- "a/problems/1365.346円234円211円345円244円232円345円260円221円345円260円217円344円272円216円345円275円223円345円211円215円346円225円260円345円255円227円347円232円204円346円225円260円345円255円227円.md"
+++ "b/problems/1365.346円234円211円345円244円232円345円260円221円345円260円217円344円272円216円345円275円223円345円211円215円346円225円260円345円255円227円347円232円204円346円225円260円345円255円227円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1382.345円260円206円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円345円217円230円345円271円263円350円241円241円.md" "b/problems/1382.345円260円206円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円345円217円230円345円271円263円350円241円241円.md"
old mode 100644
new mode 100755
index 120cafffd3..551766ff0d
--- "a/problems/1382.345円260円206円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円345円217円230円345円271円263円350円241円241円.md"
+++ "b/problems/1382.345円260円206円344円272円214円345円217円211円346円220円234円347円264円242円346円240円221円345円217円230円345円271円263円350円241円241円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1791.346円211円276円345円207円272円346円230円237円345円236円213円345円233円276円347円232円204円344円270円255円345円277円203円350円212円202円347円202円271円.md" "b/problems/1791.346円211円276円345円207円272円346円230円237円345円236円213円345円233円276円347円232円204円344円270円255円345円277円203円350円212円202円347円202円271円.md"
old mode 100644
new mode 100755
index e3db794706..9991249f5a
--- "a/problems/1791.346円211円276円345円207円272円346円230円237円345円236円213円345円233円276円347円232円204円344円270円255円345円277円203円350円212円202円347円202円271円.md"
+++ "b/problems/1791.346円211円276円345円207円272円346円230円237円345円236円213円345円233円276円347円232円204円344円270円255円345円277円203円350円212円202円347円202円271円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/1971.345円257円273円346円211円276円345円233円276円344円270円255円346円230円257円345円220円246円345円255円230円345円234円250円350円267円257円345円276円204円.md" "b/problems/1971.345円257円273円346円211円276円345円233円276円344円270円255円346円230円257円345円220円246円345円255円230円345円234円250円350円267円257円345円276円204円.md"
old mode 100644
new mode 100755
index 93e9b66365..9048b0f6af
--- "a/problems/1971.345円257円273円346円211円276円345円233円276円344円270円255円346円230円257円345円220円246円345円255円230円345円234円250円350円267円257円345円276円204円.md"
+++ "b/problems/1971.345円257円273円346円211円276円345円233円276円344円270円255円346円230円257円345円220円246円345円255円230円345円234円250円350円267円257円345円276円204円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/O(n)347円232円204円347円256円227円346円263円225円345円261円205円347円204円266円350円266円205円346円227円266円344円272円206円357円274円214円346円255円244円346円227円266円347円232円204円n347円251円266円347円253円237円346円230円257円345円244円232円345円244円247円357円274円237円.md" "b/problems/O(n)347円232円204円347円256円227円346円263円225円345円261円205円347円204円266円350円266円205円346円227円266円344円272円206円357円274円214円346円255円244円346円227円266円347円232円204円n347円251円266円347円253円237円346円230円257円345円244円232円345円244円247円357円274円237円.md"
index a5dab942c8..d74f1a01aa 100644
--- "a/problems/O(n)347円232円204円347円256円227円346円263円225円345円261円205円347円204円266円350円266円205円346円227円266円344円272円206円357円274円214円346円255円244円346円227円266円347円232円204円n347円251円266円347円253円237円346円230円257円345円244円232円345円244円247円357円274円237円.md"
+++ "b/problems/O(n)347円232円204円347円256円227円346円263円225円345円261円205円347円204円266円350円266円205円346円227円266円344円272円206円357円274円214円346円255円244円346円227円266円347円232円204円n347円251円266円347円253円237円346円230円257円345円244円232円345円244円247円357円274円237円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/images/0110.345円255円227円347円254円246円344円270円262円346円216円245円351円276円231円-03.png" "b/problems/images/0110.345円255円227円347円254円246円344円270円262円346円216円245円351円276円231円-03.png"
new file mode 100644
index 0000000000..7ad2ced690
Binary files /dev/null and "b/problems/images/0110.345円255円227円347円254円246円344円270円262円346円216円245円351円276円231円-03.png" differ
diff --git "a/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra345円240円206円.md" "b/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra345円240円206円.md"
index 75c12f8a96..fceef23926 100644
--- "a/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra345円240円206円.md"
+++ "b/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra345円240円206円.md"
@@ -46,13 +46,13 @@
如下图所示,起始车站为 1 号车站,终点车站为 7 号车站,绿色路线为最短的路线,路线总长度为 12,则输出 12。
-
+
不能到达的情况:
如下图所示,当从起始车站不能到达终点车站时,则输出 -1。
-
+
数据范围:
@@ -101,7 +101,7 @@
如图:
-
+
在一个 n (节点数)为8 的图中,就需要申请 8 * 8 这么大的空间,有一条双向边,即:grid[2][5] = 6,grid[5][2] = 6
@@ -125,7 +125,7 @@
邻接表的构造如图:
-
+
这里表达的图是:
@@ -210,7 +210,7 @@ vector 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
+
参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益! ' -cx $i
+ # ex -sc '1i| 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益! ' -cx $i
+
+ ex -sc '1i|* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html)' -cx $i
+ ex -sc '1i|* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html)' -cx $i
+ ex -sc '1i|* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html)' -cx $i
+
+
# echo '## 其他语言版本'>> $i
# echo '\n'>> $i
# echo 'Java:'>> $i
@@ -48,10 +54,10 @@ do
# 添加结尾
- echo ' '>> $i
- echo ''>> $i
- echo ' '>> $i
- echo ''>> $i
+ # echo ' '>> $i
+ # echo ''>> $i
+ # echo ' '>> $i
+ # echo ''>> $i
# echo '-----------------------'>> $i
diff --git "a/problems/344円270円272円344円272円206円347円273円235円346円235円200円347円274円226円350円276円221円350円267円235円347円246円273円357円274円214円345円215円241円345円260円224円345円201円232円344円272円206円344円270円211円346円255円245円351円223円272円345円236円253円.md" "b/problems/344円270円272円344円272円206円347円273円235円346円235円200円347円274円226円350円276円221円350円267円235円347円246円273円357円274円214円345円215円241円345円260円224円345円201円232円344円272円206円344円270円211円346円255円245円351円223円272円345円236円253円.md"
old mode 100644
new mode 100755
index c2f5efd96d..69d6aa9c45
--- "a/problems/344円270円272円344円272円206円347円273円235円346円235円200円347円274円226円350円276円221円350円267円235円347円246円273円357円274円214円345円215円241円345円260円224円345円201円232円344円272円206円344円270円211円346円255円245円351円223円272円345円236円253円.md"
+++ "b/problems/344円270円272円344円272円206円347円273円235円346円235円200円347円274円226円350円276円221円350円267円235円347円246円273円357円274円214円345円215円241円345円260円224円345円201円232円344円272円206円344円270円211円346円255円245円351円223円272円345円236円253円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/344円272円214円345円217円211円346円240円221円344円270円255円351円200円222円345円275円222円345円270円246円347円235円200円345円233円236円346円272円257円.md" "b/problems/344円272円214円345円217円211円346円240円221円344円270円255円351円200円222円345円275円222円345円270円246円347円235円200円345円233円236円346円272円257円.md"
old mode 100644
new mode 100755
index 42d78ae39f..7fa2b6ec94
--- "a/problems/344円272円214円345円217円211円346円240円221円344円270円255円351円200円222円345円275円222円345円270円246円347円235円200円345円233円236円346円272円257円.md"
+++ "b/problems/344円272円214円345円217円211円346円240円221円344円270円255円351円200円222円345円275円222円345円270円246円347円235円200円345円233円236円346円272円257円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/344円272円214円345円217円211円346円240円221円346円200円273円347円273円223円347円257円207円.md" "b/problems/344円272円214円345円217円211円346円240円221円346円200円273円347円273円223円347円257円207円.md"
old mode 100644
new mode 100755
index 4794233ab5..7d25d81876
--- "a/problems/344円272円214円345円217円211円346円240円221円346円200円273円347円273円223円347円257円207円.md"
+++ "b/problems/344円272円214円345円217円211円346円240円221円346円200円273円347円273円223円347円257円207円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/344円272円214円345円217円211円346円240円221円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/344円272円214円345円217円211円346円240円221円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index c665827791..a68f93a901
--- "a/problems/344円272円214円345円217円211円346円240円221円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/344円272円214円345円217円211円346円240円221円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/344円272円214円345円217円211円346円240円221円347円232円204円347円273円237円344円270円200円350円277円255円344円273円243円346円263円225円.md" "b/problems/344円272円214円345円217円211円346円240円221円347円232円204円347円273円237円344円270円200円350円277円255円344円273円243円346円263円225円.md"
old mode 100644
new mode 100755
index a6d4e3ffc3..803b25ae80
--- "a/problems/344円272円214円345円217円211円346円240円221円347円232円204円347円273円237円344円270円200円350円277円255円344円273円243円346円263円225円.md"
+++ "b/problems/344円272円214円345円217円211円346円240円221円347円232円204円347円273円237円344円270円200円350円277円255円344円273円243円346円263円225円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/344円272円214円345円217円211円346円240円221円347円232円204円350円277円255円344円273円243円351円201円215円345円216円206円.md" "b/problems/344円272円214円345円217円211円346円240円221円347円232円204円350円277円255円344円273円243円351円201円215円345円216円206円.md"
old mode 100644
new mode 100755
index a3c5b38fa0..efa07d97d9
--- "a/problems/344円272円214円345円217円211円346円240円221円347円232円204円350円277円255円344円273円243円351円201円215円345円216円206円.md"
+++ "b/problems/344円272円214円345円217円211円346円240円221円347円232円204円350円277円255円344円273円243円351円201円215円345円216円206円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/344円272円214円345円217円211円346円240円221円347円232円204円351円200円222円345円275円222円351円201円215円345円216円206円.md" "b/problems/344円272円214円345円217円211円346円240円221円347円232円204円351円200円222円345円275円222円351円201円215円345円216円206円.md"
old mode 100644
new mode 100755
index 8f61b8c69a..ffa3ff6cf8
--- "a/problems/344円272円214円345円217円211円346円240円221円347円232円204円351円200円222円345円275円222円351円201円215円345円216円206円.md"
+++ "b/problems/344円272円214円345円217円211円346円240円221円347円232円204円351円200円222円345円275円222円351円201円215円345円216円206円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円211円215円345円272円217円/ACM346円250円241円345円274円217円.md" "b/problems/345円211円215円345円272円217円/ACM346円250円241円345円274円217円.md"
index 313264fba2..70643b7e49 100644
--- "a/problems/345円211円215円345円272円217円/ACM346円250円241円345円274円217円.md"
+++ "b/problems/345円211円215円345円272円217円/ACM346円250円241円345円274円217円.md"
@@ -5,15 +5,15 @@
平时大家在力扣上刷题,就是 核心代码模式,即给你一个函数,直接写函数实现,例如这样:
-
+
而ACM模式,是程序头文件,main函数,数据的输入输出都要自己处理,例如这样:
-
+
大家可以发现 右边代码框什么都没有,程序从头到尾都需要自己实现,本题如果写完代码是这样的: (细心的录友可以发现和力扣上刷题是不一样的)
-
+
**如果大家从一开始学习算法就一直在力扣上的话,突然切到ACM模式会非常不适应**。
@@ -21,15 +21,15 @@
知识星球里也有很多录友,因为不熟悉ACM模式在面试的过程中吃了不少亏。
- 欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益! 欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益! 欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益! 欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益! 欢迎大家参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円211円221円346円214円207円Offer58-II.345円267円246円346円227円213円350円275円254円345円255円227円347円254円246円344円270円262円.md" "b/problems/345円211円221円346円214円207円Offer58-II.345円267円246円346円227円213円350円275円254円345円255円227円347円254円246円344円270円262円.md"
old mode 100644
new mode 100755
index e32f4ce15d..025073220a
--- "a/problems/345円211円221円346円214円207円Offer58-II.345円267円246円346円227円213円350円275円254円345円255円227円347円254円246円344円270円262円.md"
+++ "b/problems/345円211円221円346円214円207円Offer58-II.345円267円246円346円227円213円350円275円254円345円255円227円347円254円246円344円270円262円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円212円250円346円200円201円350円247円204円345円210円222円-350円202円241円347円245円250円351円227円256円351円242円230円346円200円273円347円273円223円347円257円207円.md" "b/problems/345円212円250円346円200円201円350円247円204円345円210円222円-350円202円241円347円245円250円351円227円256円351円242円230円346円200円273円347円273円223円347円257円207円.md"
old mode 100644
new mode 100755
index 7927deb7d7..ff73cd9606
--- "a/problems/345円212円250円346円200円201円350円247円204円345円210円222円-350円202円241円347円245円250円351円227円256円351円242円230円346円200円273円347円273円223円347円257円207円.md"
+++ "b/problems/345円212円250円346円200円201円350円247円204円345円210円222円-350円202円241円347円245円250円351円227円256円351円242円230円346円200円273円347円273円223円347円257円207円.md"
@@ -1,14 +1,12 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円212円250円346円200円201円350円247円204円345円210円222円346円200円273円347円273円223円347円257円207円.md" "b/problems/345円212円250円346円200円201円350円247円204円345円210円222円346円200円273円347円273円223円347円257円207円.md"
old mode 100644
new mode 100755
index dd1646d6d8..83d88cf448
--- "a/problems/345円212円250円346円200円201円350円247円204円345円210円222円346円200円273円347円273円223円347円257円207円.md"
+++ "b/problems/345円212円250円346円200円201円350円247円204円345円210円222円346円200円273円347円273円223円347円257円207円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円212円250円346円200円201円350円247円204円345円210円222円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/345円212円250円346円200円201円350円247円204円345円210円222円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index 9ffb453377..63f059798e
--- "a/problems/345円212円250円346円200円201円350円247円204円345円210円222円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/345円212円250円346円200円201円350円247円204円345円210円222円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,14 +1,12 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円217円214円346円214円207円351円222円210円346円200円273円347円273円223円.md" "b/problems/345円217円214円346円214円207円351円222円210円346円200円273円347円273円223円.md"
old mode 100644
new mode 100755
index 409e80ab98..9c92e3d6c3
--- "a/problems/345円217円214円346円214円207円351円222円210円346円200円273円347円273円223円.md"
+++ "b/problems/345円217円214円346円214円207円351円222円210円346円200円273円347円273円223円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円221円250円346円200円273円347円273円223円/20200927344円272円214円345円217円211円346円240円221円345円221円250円346円234円253円346円200円273円347円273円223円.md" "b/problems/345円221円250円346円200円273円347円273円223円/20200927344円272円214円345円217円211円346円240円221円345円221円250円346円234円253円346円200円273円347円273円223円.md"
index 594656ca23..11dd298292 100644
--- "a/problems/345円221円250円346円200円273円347円273円223円/20200927344円272円214円345円217円211円346円240円221円345円221円250円346円234円253円346円200円273円347円273円223円.md"
+++ "b/problems/345円221円250円346円200円273円347円273円223円/20200927344円272円214円345円217円211円346円240円221円345円221円250円346円234円253円346円200円273円347円273円223円.md"
@@ -203,4 +203,4 @@ public:
**本周我们都是讲解了二叉树,从理论基础到遍历方式,从递归到迭代,从深度遍历到广度遍历,最后再用了一个翻转二叉树的题目把我们之前讲过的遍历方式都串了起来。**
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円223円210円345円270円214円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/345円223円210円345円270円214円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index 825c465719..e3400ad7f0
--- "a/problems/345円223円210円345円270円214円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/345円223円210円345円270円214円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円233円236円346円272円257円346円200円273円347円273円223円.md" "b/problems/345円233円236円346円272円257円346円200円273円347円273円223円.md"
old mode 100644
new mode 100755
index 8d9b78c4b9..7a7929f41a
--- "a/problems/345円233円236円346円272円257円346円200円273円347円273円223円.md"
+++ "b/problems/345円233円236円346円272円257円346円200円273円347円273円223円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円233円236円346円272円257円347円256円227円346円263円225円345円216円273円351円207円215円351円227円256円351円242円230円347円232円204円345円217円246円344円270円200円347円247円215円345円206円231円346円263円225円.md" "b/problems/345円233円236円346円272円257円347円256円227円346円263円225円345円216円273円351円207円215円351円227円256円351円242円230円347円232円204円345円217円246円344円270円200円347円247円215円345円206円231円346円263円225円.md"
old mode 100644
new mode 100755
index 96dfeffec3..5e2c9345c4
--- "a/problems/345円233円236円346円272円257円347円256円227円346円263円225円345円216円273円351円207円215円351円227円256円351円242円230円347円232円204円345円217円246円344円270円200円347円247円215円345円206円231円346円263円225円.md"
+++ "b/problems/345円233円236円346円272円257円347円256円227円346円263円225円345円216円273円351円207円215円351円227円256円351円242円230円347円232円204円345円217円246円344円270円200円347円247円215円345円206円231円346円263円225円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円233円236円346円272円257円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/345円233円236円346円272円257円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index 862fb101a1..c17e0be3f6
--- "a/problems/345円233円236円346円272円257円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/345円233円236円346円272円257円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,14 +1,12 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/345円255円227円347円254円246円344円270円262円346円200円273円347円273円223円.md" "b/problems/345円255円227円347円254円246円344円270円262円346円200円273円347円273円223円.md"
old mode 100644
new mode 100755
index 7da9791400..460944c5d2
--- "a/problems/345円255円227円347円254円246円344円270円262円346円200円273円347円273円223円.md"
+++ "b/problems/345円255円227円347円254円246円344円270円262円346円200円273円347円273円223円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/346円225円260円347円273円204円346円200円273円347円273円223円347円257円207円.md" "b/problems/346円225円260円347円273円204円346円200円273円347円273円223円347円257円207円.md"
old mode 100644
new mode 100755
index 7c2fd94724..98ba371fdc
--- "a/problems/346円225円260円347円273円204円346円200円273円347円273円223円347円257円207円.md"
+++ "b/problems/346円225円260円347円273円204円346円200円273円347円273円223円347円257円207円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/346円225円260円347円273円204円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/346円225円260円347円273円204円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index e6d25c15e6..49c41f5abb
--- "a/problems/346円225円260円347円273円204円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/346円225円260円347円273円204円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/346円240円210円344円270円216円351円230円237円345円210円227円346円200円273円347円273円223円.md" "b/problems/346円240円210円344円270円216円351円230円237円345円210円227円346円200円273円347円273円223円.md"
old mode 100644
new mode 100755
index df022c779b..2d09daeb94
--- "a/problems/346円240円210円344円270円216円351円230円237円345円210円227円346円200円273円347円273円223円.md"
+++ "b/problems/346円240円210円344円270円216円351円230円237円345円210円227円346円200円273円347円273円223円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/346円240円210円344円270円216円351円230円237円345円210円227円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/346円240円210円344円270円216円351円230円237円345円210円227円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index 21c61a4c8b..a33c2a880f
--- "a/problems/346円240円210円344円270円216円351円230円237円345円210円227円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/346円240円210円344円270円216円351円230円237円345円210円227円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円357円274円210円vector345円216円237円347円220円206円350円256円262円350円247円243円357円274円211円.md" "b/problems/346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円357円274円210円vector345円216円237円347円220円206円350円256円262円350円247円243円357円274円211円.md"
old mode 100644
new mode 100755
index 70a9a97a19..a3566268a1
--- "a/problems/346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円357円274円210円vector345円216円237円347円220円206円350円256円262円350円247円243円357円274円211円.md"
+++ "b/problems/346円240円271円346円215円256円350円272円253円351円253円230円351円207円215円345円273円272円351円230円237円345円210円227円357円274円210円vector345円216円237円347円220円206円350円256円262円350円247円243円357円274円211円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/347円256円227円346円263円225円346円250円241円346円235円277円.md" "b/problems/347円256円227円346円263円225円346円250円241円346円235円277円.md"
old mode 100644
new mode 100755
index 0d32cebb2d..068806d622
--- "a/problems/347円256円227円346円263円225円346円250円241円346円235円277円.md"
+++ "b/problems/347円256円227円346円263円225円346円250円241円346円235円277円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円203円214円345円214円205円346円200円273円347円273円223円347円257円207円.md" "b/problems/350円203円214円345円214円205円346円200円273円347円273円223円347円257円207円.md"
old mode 100644
new mode 100755
index 651a92a804..3f3841e1a2
--- "a/problems/350円203円214円345円214円205円346円200円273円347円273円223円347円257円207円.md"
+++ "b/problems/350円203円214円345円214円205円346円200円273円347円273円223円347円257円207円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md" "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md"
old mode 100644
new mode 100755
index d9b953c0b3..d3258c425e
--- "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md"
+++ "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-1.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md" "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md"
old mode 100644
new mode 100755
index b5862bb52b..00dc593417
--- "a/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md"
+++ "b/problems/350円203円214円345円214円205円347円220円206円350円256円272円345円237円272円347円241円20001円350円203円214円345円214円205円-2.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円203円214円345円214円205円351円227円256円351円242円230円345円256円214円345円205円250円350円203円214円345円214円205円344円270円200円347円273円264円.md" "b/problems/350円203円214円345円214円205円351円227円256円351円242円230円345円256円214円345円205円250円350円203円214円345円214円205円344円270円200円347円273円264円.md"
index a8e241c3ba..7dd78302ee 100644
--- "a/problems/350円203円214円345円214円205円351円227円256円351円242円230円345円256円214円345円205円250円350円203円214円345円214円205円344円270円200円347円273円264円.md"
+++ "b/problems/350円203円214円345円214円205円351円227円256円351円242円230円345円256円214円345円205円250円350円203円214円345円214円205円344円270円200円347円273円264円.md"
@@ -1,3 +1,6 @@
+* [做项目(多个C++、Java、Go、测开、前端项目)](https://www.programmercarl.com/other/kstar.html)
+* [刷算法(两个月高强度学算法)](https://www.programmercarl.com/xunlian/xunlianying.html)
+* [背八股(40天挑战高频面试题)](https://www.programmercarl.com/xunlian/bagu.html)
# 完全背包-一维数组
@@ -51,11 +54,11 @@ for (int i = 1; i < n; i++) { // 遍历物品 遍历物品在外层循环,遍历背包容量在内层循环,状态如图: - + 遍历背包容量在外层循环,遍历物品在内层循环,状态如图: - + 看了这两个图,大家就会理解,完全背包中,两个for循环的先后循序,都不影响计算dp[j]所需要的值(这个值就是下标j之前所对应的dp[j])。 diff --git "a/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円244円232円351円207円215円350円203円214円345円214円205円.md" "b/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円244円232円351円207円215円350円203円214円345円214円205円.md" old mode 100644 new mode 100755 index 878efc1297..39e7ebe378 --- "a/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円244円232円351円207円215円350円203円214円345円214円205円.md" +++ "b/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円244円232円351円207円215円350円203円214円345円214円205円.md" @@ -1,8 +1,6 @@ -
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円256円214円345円205円250円350円203円214円345円214円205円.md" "b/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円256円214円345円205円250円350円203円214円345円214円205円.md"
old mode 100644
new mode 100755
index ea658f7e51..02b3cdc32d
--- "a/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円256円214円345円205円250円350円203円214円345円214円205円.md"
+++ "b/problems/350円203円214円345円214円205円351円227円256円351円242円230円347円220円206円350円256円272円345円237円272円347円241円200円345円256円214円345円205円250円350円203円214円345円214円205円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円264円252円345円277円203円347円256円227円346円263円225円346円200円273円347円273円223円347円257円207円.md" "b/problems/350円264円252円345円277円203円347円256円227円346円263円225円346円200円273円347円273円223円347円257円207円.md"
old mode 100644
new mode 100755
index 14d82151c9..7aff85764e
--- "a/problems/350円264円252円345円277円203円347円256円227円346円263円225円346円200円273円347円273円223円347円257円207円.md"
+++ "b/problems/350円264円252円345円277円203円347円256円227円346円263円225円346円200円273円347円273円223円347円257円207円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/350円264円252円345円277円203円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/350円264円252円345円277円203円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index 6fde2dbbe6..3bcf307525
--- "a/problems/350円264円252円345円277円203円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/350円264円252円345円277円203円347円256円227円346円263円225円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,15 +1,13 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/351円200円222円345円275円222円347円256円227円346円263円225円347円232円204円346円227円266円351円227円264円344円270円216円347円251円272円351円227円264円345円244円215円346円235円202円345円272円246円345円210円206円346円236円220円.md" "b/problems/351円200円222円345円275円222円347円256円227円346円263円225円347円232円204円346円227円266円351円227円264円344円270円216円347円251円272円351円227円264円345円244円215円346円235円202円345円272円246円345円210円206円346円236円220円.md"
new file mode 100755
index 0000000000..98aa47a865
--- /dev/null
+++ "b/problems/351円200円222円345円275円222円347円256円227円346円263円225円347円232円204円346円227円266円351円227円264円344円270円216円347円251円272円351円227円264円345円244円215円346円235円202円345円272円246円345円210円206円346円236円220円.md"
@@ -0,0 +1,281 @@
+* [做项目(多个C++、Java、Go、测开、前端项目)](./other/kstar.md)
+* [刷算法(两个月高强度学算法)](./xunlian/xunlianying.md)
+* [背八股(40天挑战高频面试题)](./xunlian/bagu.md)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# 递归算法的时间与空间复杂度分析!
+
+之前在[通过一道面试题目,讲一讲递归算法的时间复杂度!](https://programmercarl.com/前序/通过一道面试题目,讲一讲递归算法的时间复杂度!.html)中详细讲解了递归算法的时间复杂度,但没有讲空间复杂度。
+
+本篇讲通过求斐波那契数列和二分法再来深入分析一波递归算法的时间和空间复杂度,细心看完,会刷新对递归的认知!
+
+
+## 递归求斐波那契数列的性能分析
+
+先来看一下求斐波那契数的递归写法。
+
+```CPP
+int fibonacci(int i) {
+ if(i <= 0) return 0; + if(i == 1) return 1; + return fibonacci(i-1) + fibonacci(i-2); +} +``` + +对于递归算法来说,代码一般都比较简短,从算法逻辑上看,所用的存储空间也非常少,但运行时需要内存可不见得会少。 + +### 时间复杂度分析 + +来看看这个求斐波那契的递归算法的时间复杂度是多少呢? + +在讲解递归时间复杂度的时候,我们提到了递归算法的时间复杂度本质上是要看: **递归的次数 * 每次递归的时间复杂度**。 + +可以看出上面的代码每次递归都是O(1)的操作。再来看递归了多少次,这里将i为5作为输入的递归过程 抽象成一棵递归树,如图: + + + + +从图中,可以看出f(5)是由f(4)和f(3)相加而来,那么f(4)是由f(3)和f(2)相加而来 以此类推。 + +在这棵二叉树中每一个节点都是一次递归,那么这棵树有多少个节点呢? + +我们之前也有说到,一棵深度(按根节点深度为1)为k的二叉树最多可以有 2^k - 1 个节点。 + +所以该递归算法的时间复杂度为O(2^n),这个复杂度是非常大的,随着n的增大,耗时是指数上升的。 + +来做一个实验,大家可以有一个直观的感受。 + +以下为C++代码,来测一下,让我们输入n的时候,这段递归求斐波那契代码的耗时。 + +```CPP +#include
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
old mode 100644
new mode 100755
index d131380728..c465818739
--- "a/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
diff --git "a/problems/351円235円242円350円257円225円351円242円23002円.07.351円223円276円350円241円250円347円233円270円344円272円244円.md" "b/problems/351円235円242円350円257円225円351円242円23002円.07.351円223円276円350円241円250円347円233円270円344円272円244円.md"
old mode 100644
new mode 100755
index 48944b5e4e..7e23172093
--- "a/problems/351円235円242円350円257円225円351円242円23002円.07.351円223円276円350円241円250円347円233円270円344円272円244円.md"
+++ "b/problems/351円235円242円350円257円225円351円242円23002円.07.351円223円276円350円241円250円347円233円270円344円272円244円.md"
@@ -1,8 +1,6 @@
-
-
-
-
- 参与本项目,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!
-
-
-
> grid(n + 1);
不少录友,不知道 如何定义的数据结构,怎么表示邻接表的,我来给大家画一个图:
-
+
图中邻接表表示:
@@ -781,7 +784,7 @@ vector
>> grid(n + 1);
举例来给大家展示 该代码表达的数据 如下:
-
+
* 节点1 指向 节点3 权值为 1
* 节点1 指向 节点5 权值为 2
@@ -904,7 +907,7 @@ for (int v = 1; v <= n; v++) { 再回顾一下邻接表的构造(数组 + 链表): - + 假如 加入的cur 是节点 2, 那么 grid[2] 表示的就是图中第二行链表。 (grid数组的构造我们在 上面 「图的存储」中讲过) diff --git "a/problems/0746.344円275円277円347円224円250円346円234円200円345円260円217円350円212円261円350円264円271円347円210円254円346円245円274円346円242円257円.md" "b/problems/0746.344円275円277円347円224円250円346円234円200円345円260円217円350円212円261円350円264円271円347円210円254円346円245円274円346円242円257円.md" old mode 100644 new mode 100755 index 753a104d97..952d4d2ab7 --- "a/problems/0746.344円275円277円347円224円250円346円234円200円345円260円217円350円212円261円350円264円271円347円210円254円346円245円274円346円242円257円.md" +++ "b/problems/0746.344円275円277円347円224円250円346円234円200円345円260円217円350円212円261円350円264円271円347円210円254円346円245円274円346円242円257円.md" @@ -1,8 +1,6 @@ -
> grid(n + 1);
不少录友,不知道 如何定义的数据结构,怎么表示邻接表的,我来给大家画一个图:
-
+
图中邻接表表示:
@@ -231,7 +231,7 @@ vector
>> grid(n + 1);
举例来给大家展示 该代码表达的数据 如下:
-
+
* 节点1 指向 节点3 权值为 1
* 节点1 指向 节点5 权值为 2
@@ -354,7 +354,7 @@ for (int v = 1; v <= n; v++) { 再回顾一下邻接表的构造(数组 + 链表): - + 假如 加入的cur 是节点 2, 那么 grid[2] 表示的就是图中第二行链表。 (grid数组的构造我们在 上面 「图的存储」中讲过) diff --git "a/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra346円234円264円347円264円240円.md" "b/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra346円234円264円347円264円240円.md" index e71e9d5374..47ef1625bd 100644 --- "a/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra346円234円264円347円264円240円.md" +++ "b/problems/kamacoder/0047.345円217円202円344円274円232円dijkstra346円234円264円347円264円240円.md" @@ -46,13 +46,13 @@ 如下图所示,起始车站为 1 号车站,终点车站为 7 号车站,绿色路线为最短的路线,路线总长度为 12,则输出 12。 - + 不能到达的情况: 如下图所示,当从起始车站不能到达终点车站时,则输出 -1。 - + 数据范围: @@ -76,7 +76,7 @@ dijkstra算法:在有权图(权值非负数)中求从起点到其他节点 如本题示例中的图: - + 起点(节点1)到终点(节点7) 的最短路径是 图中 标记绿线的部分。 @@ -114,7 +114,7 @@ dijkstra 算法 同样是贪心的思路,不断寻找距离 源点最近的没 ### 模拟过程 ------------ +----------- 0、初始化 @@ -122,7 +122,7 @@ minDist数组数值初始化为int最大值。 这里在强点一下 **minDist数组的含义:记录所有节点到源点的最短路径**,那么初始化的时候就应该初始为最大值,这样才能在后续出现最短路径的时候及时更新。 - + (图中,max 表示默认值,节点0 不做处理,统一从下标1 开始计算,这样下标和节点数值统一, 方便大家理解,避免搞混) @@ -130,7 +130,7 @@ minDist数组数值初始化为int最大值。 此时所有节点都没有被访问过,所以 visited数组都为0 ---------------- +--------------- 以下为dijkstra 三部曲 @@ -144,7 +144,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 更新 minDist数组,即:源点(节点1) 到 节点2 和 节点3的距离。 @@ -170,7 +170,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 更新 minDist数组,即:源点(节点1) 到 节点6 、 节点3 和 节点4的距离。 @@ -204,7 +204,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 由于节点3的加入,那么源点可以有新的路径链接到节点4 所以更新minDist数组: @@ -224,7 +224,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 由于节点4的加入,那么源点可以链接到节点5 所以更新minDist数组: @@ -244,7 +244,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 由于节点6的加入,那么源点可以链接到节点7 所以 更新minDist数组: @@ -264,7 +264,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 由于节点5的加入,那么源点有新的路径可以链接到节点7 所以 更新minDist数组: @@ -282,7 +282,7 @@ minDist数组数值初始化为int最大值。 3、更新非访问节点到源点的距离(即更新minDist数组) ,如图: - + 节点7加入,但节点7到节点7的距离为0,所以 不用更新minDist数组 @@ -296,7 +296,7 @@ minDist数组数值初始化为int最大值。 路径如图: - + 在上面的讲解中,每一步 我都是按照 dijkstra 三部曲来讲解的,理解了这三部曲,代码也就好懂的。 @@ -541,7 +541,7 @@ int main() { 对应如图: - + ### 出现负数 @@ -549,19 +549,19 @@ int main() { 看一下这个图: (有负权值) - + 节点1 到 节点5 的最短路径 应该是 节点1 -> 节点2 -> 节点3 -> 节点4 -> 节点5
那我们来看dijkstra 求解的路径是什么样的,继续dijkstra 三部曲来模拟 :(dijkstra模拟过程上面已经详细讲过,以下只模拟重要过程,例如如何初始化就省略讲解了)
------------
+-----------
初始化:
-
+
----------------
+---------------
1、选源点到哪个节点近且该节点未被访问过
@@ -573,7 +573,7 @@ int main() {
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
更新 minDist数组,即:源点(节点1) 到 节点2 和 节点3的距离。
@@ -592,7 +592,7 @@ int main() {
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点3的加入,那么源点可以有新的路径链接到节点4 所以更新minDist数组:
@@ -610,7 +610,7 @@ int main() {
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
由于节点4的加入,那么源点可以有新的路径链接到节点5 所以更新minDist数组:
@@ -628,11 +628,11 @@ int main() {
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
节点5的加入,而节点5 没有链接其他节点, 所以不用更新minDist数组,仅标记节点5被访问过了
-------------
+------------
1、选源点到哪个节点近且该节点未被访问过
@@ -644,9 +644,9 @@ int main() {
3、更新非访问节点到源点的距离(即更新minDist数组) ,如图:
-
+
---------------
+--------------
至此dijkstra的模拟过程就结束了,根据最后的minDist数组,我们求 节点1 到 节点5 的最短路径的权值总和为 3,路径: 节点1 -> 节点3 -> 节点4 -> 节点5
@@ -865,6 +865,114 @@ if __name__ == "__main__":
### Go
+```go
+package main
+
+import(
+ "fmt"
+ "os"
+ "bufio"
+ "strconv"
+ "strings"
+ "math"
+)
+
+func main() {
+ // 创建Reader从标准输入中读取数据
+ reader := bufio.NewReader(os.Stdin)
+
+ // 以字符串的形式读取一行
+ line, _ := reader.ReadString('\n')
+ // 去掉字符串前后可能存在的空格
+ line = strings.TrimSpace(line)
+ // 以空格作为分隔符分割字符串,得到数字的字符串形式
+ params := strings.Split(line, " ")
+ // 字符串转化为数字,得到n和m,其中n为汽车站数,m为公路数
+ n, _ := strconv.Atoi(params[0])
+ m, _ := strconv.Atoi(params[1])
+
+ // 存储从源点到每个节点的最短距离
+ minDist := initSliceInt(math.MaxInt32, n + 1)
+ minDist[1] = 0
+ // 记录顶点是否被访问过
+ visited := initSliceBool(false, n + 1)
+
+ // 存储每个车站之间的距离
+ grid := make([][]int, n + 1)
+ for i := 1; i <= n; i++ { + grid[i] = initSliceInt(math.MaxInt32, n + 1) + grid[i][i] = 0 + } + for i := 1; i <= m; i++ { + line, _ = reader.ReadString('\n') + line = strings.TrimSpace(line) + params = strings.Split(line, " ") + a, _ := strconv.Atoi(params[0]) + b, _ := strconv.Atoi(params[1]) + c, _ := strconv.Atoi(params[2]) + + grid[a][b] = c + } + + // Dijkstra算法 + for i := 1; i <= n; i++ { + cur := -1 + // 1、选距离源点最近且未访问过的节点 + for j := 1; j <= n; j++ { + if visited[j] == false && (cur == -1 || minDist[cur]> minDist[j]) {
+ cur = j;
+ }
+ }
+
+ // 2、标记该节点已被访问
+ visited[cur] = true
+
+ /*
+ 3、更新非访问节点到源点的距离(即更新minDist数组)。实际更新时无需判断
+ 节点是否被访问过,因为1.的限制,即使更新被访问过的点也没有任何影响。
+ */
+ for j := 1; j <= n; j++ { + minDist[j] = min(minDist[j], minDist[cur] + grid[cur][j]) + } + + } + + if minDist[n] == math.MaxInt32 { + // 不能到达终点 + fmt.Print(-1) + } else { + // 到达终点最短路径 + fmt.Print(minDist[n]) + } +} + +// 创建int类型的切片 +func initSliceInt(value int, count int) []int { + result := make([]int, count) + for i := range result { + result[i] = value + } + return result +} + +// 创建bool类型的切片 +func initSliceBool(value bool, count int) []bool { + result := make([]bool, count) + for i := range result { + result[i] = value + } + return result +} + +// 比较两个int类型的大小,返回较小的一个 +func min(a, b int) int { + if a> b {
+ return b
+ }
+ return a
+}
+```
+
### Rust
### JavaScript
diff --git "a/problems/kamacoder/0053.345円257円273円345円256円235円-Kruskal.md" "b/problems/kamacoder/0053.345円257円273円345円256円235円-Kruskal.md"
index 861efe6806..a7022c5d08 100644
--- "a/problems/kamacoder/0053.345円257円273円345円256円235円-Kruskal.md"
+++ "b/problems/kamacoder/0053.345円257円273円345円256円235円-Kruskal.md"
@@ -63,7 +63,7 @@ kruscal的思路:
依然以示例中,如下这个图来举例。
-
+
将图中的边按照权值有小到大排序,这样从贪心的角度来说,优先选 权值小的边加入到 最小生成树中。
@@ -77,13 +77,13 @@ kruscal的思路:
选边(1,2),节点1 和 节点2 不在同一个集合,所以生成树可以添加边(1,2),并将 节点1,节点2 放在同一个集合。
-
+
--------
选边(4,5),节点4 和 节点 5 不在同一个集合,生成树可以添加边(4,5) ,并将节点4,节点5 放到同一个集合。
-
+
**大家判断两个节点是否在同一个集合,就看图中两个节点是否有绿色的粗线连着就行**
@@ -93,25 +93,25 @@ kruscal的思路:
选边(1,3),节点1 和 节点3 不在同一个集合,生成树添加边(1,3),并将节点1,节点3 放到同一个集合。
-
+
---------
选边(2,6),节点2 和 节点6 不在同一个集合,生成树添加边(2,6),并将节点2,节点6 放到同一个集合。
-
+
--------
选边(3,4),节点3 和 节点4 不在同一个集合,生成树添加边(3,4),并将节点3,节点4 放到同一个集合。
-
+
----------
选边(6,7),节点6 和 节点7 不在同一个集合,生成树添加边(6,7),并将 节点6,节点7 放到同一个集合。
-
+
-----------
@@ -126,7 +126,7 @@ kruscal的思路:
此时 我们就已经生成了一个最小生成树,即:
-
+
在上面的讲解中,看图的话 大家知道如何判断 两个节点 是否在同一个集合(是否有绿色的线连在一起),以及如何把两个节点加入集合(就在图中把两个节点连上)
@@ -346,7 +346,7 @@ int main() {
大家可能发现 怎么和我们 模拟画的图不一样,差别在于 代码生成的最小生成树中 节点5 和 节点7相连的。
-
+
其实造成这个差别 是对边排序的时候 权值相同的边先后顺序的问题导致的,无论相同权值边的顺序是什么样的,最后都能得出最小生成树。
@@ -366,7 +366,7 @@ Kruskal 与 prim 的关键区别在于,prim维护的是节点的集合,而 K
节点未必一定要连着边那, 例如 这个图,大家能明显感受到边没有那么多对吧,但节点数量 和 上述我们讲的例子是一样的。
-
+
为什么边少的话,使用 Kruskal 更优呢?
diff --git "a/problems/kamacoder/0053.345円257円273円345円256円235円-prim.md" "b/problems/kamacoder/0053.345円257円273円345円256円235円-prim.md"
index 8e26bea4bd..d3f0aeb373 100644
--- "a/problems/kamacoder/0053.345円257円273円345円256円235円-prim.md"
+++ "b/problems/kamacoder/0053.345円257円273円345円256円235円-prim.md"
@@ -61,7 +61,7 @@
例如本题示例中的无向有权图为:
-
+
那么在这个图中,如何选取n-1条边使得图中所有节点连接到一起,并且边的权值和最小呢?
@@ -100,7 +100,7 @@ minDist数组里的数值初始化为最大数,因为本题节点距离不会
如图:
-
+
开始构造最小生成树
@@ -118,7 +118,7 @@ minDist数组里的数值初始化为最大数,因为本题节点距离不会
接下来,我们要更新所有节点距离最小生成树的距离,如图:
-
+
注意下标0,我们就不管它了,下标1与节点1对应,这样可以避免大家把节点搞混。
@@ -148,7 +148,7 @@ minDist数组里的数值初始化为最大数,因为本题节点距离不会
接下来,我们要更新节点距离最小生成树的距离,如图:
-
+
此时所有非生成树的节点距离最小生成树(节点1、节点2)的距离都已经跟新了。
@@ -172,7 +172,7 @@ minDist数组里的数值初始化为最大数,因为本题节点距离不会
接下来更新节点距离最小生成树的距离,如图:
-
+
所有非生成树的节点距离最小生成树(节点1、节点2、节点3)的距离都已经跟新了。
@@ -188,7 +188,7 @@ minDist数组里的数值初始化为最大数,因为本题节点距离不会
继续选择一个距离最小生成树(节点1、节点2、节点3)最近的非生成树里的节点,为了巩固大家对minDist数组的理解,这里我再啰嗦一遍:
-
+
**minDist数组是记录了所有非生成树节点距离生成树的最小距离**,所以从数组里我们能看出来,非生成树节点4和节点6距离生成树最近。
@@ -209,7 +209,7 @@ minDist数组里的数值初始化为最大数,因为本题节点距离不会
接下来更新节点距离最小生成树的距离,如图:
-
+
minDist数组已经更新了所有非生成树的节点距离最小生成树(节点1、节点2、节点3、节点4)的距离。
@@ -232,7 +232,7 @@ minDist数组已经更新了所有非生成树的节点距离最小生成树(
接下来更新节点距离最小生成树的距离,如图:
-
+
minDist数组已经更新了所有非生成树的节点距离最小生成树(节点1、节点2、节点3、节点4、节点5)的距离。
@@ -253,11 +253,11 @@ minDist数组已经更新了所有非生成树的节点距离最小生成树(
节点1、节点2、节点3、节点4、节点5、节点6算是最小生成树的节点,接下来更新节点距离最小生成树的距离,如图:
-
+
这里就不在重复描述了,大家类推,最后,节点7加入生成树,如图:
-
+
### 最后
@@ -478,7 +478,7 @@ int main() {
大家可以和我们本题最后生成的最小生成树的图去对比一下边的链接情况:
-
+
绿色的边是最小生成树,和我们的输出完全一致。
diff --git "a/problems/kamacoder/0054.346円233円277円346円215円242円346円225円260円345円255円227円.md" "b/problems/kamacoder/0054.346円233円277円346円215円242円346円225円260円345円255円227円.md"
index f788d65ba7..6679f68bb6 100644
--- "a/problems/kamacoder/0054.346円233円277円346円215円242円346円225円260円345円255円227円.md"
+++ "b/problems/kamacoder/0054.346円233円277円346円215円242円346円225円260円345円255円227円.md"
@@ -29,11 +29,11 @@
如图:
-
+
然后从后向前替换数字字符,也就是双指针法,过程如下:i指向新长度的末尾,j指向旧长度的末尾。
-
+
有同学问了,为什么要从后向前填充,从前向后填充不行么?
diff --git "a/problems/kamacoder/0055.345円217円263円346円227円213円345円255円227円347円254円246円344円270円262円.md" "b/problems/kamacoder/0055.345円217円263円346円227円213円345円255円227円347円254円246円344円270円262円.md"
index 2b32cb44d2..b0918f4eea 100644
--- "a/problems/kamacoder/0055.345円217円263円346円227円213円345円255円227円347円254円246円344円270円262円.md"
+++ "b/problems/kamacoder/0055.345円217円263円346円227円213円345円255円227円347円254円246円344円270円262円.md"
@@ -40,16 +40,16 @@ fgabcde
本题中,我们需要将字符串右移n位,字符串相当于分成了两个部分,如果n为2,符串相当于分成了两个部分,如图: (length为字符串长度)
-
+
右移n位, 就是将第二段放在前面,第一段放在后面,先不考虑里面字符的顺序,是不是整体倒叙不就行了。如图:
-
+
此时第一段和第二段的顺序是我们想要的,但里面的字符位置被我们倒叙,那么此时我们在把 第一段和第二段里面的字符再倒叙一把,这样字符顺序不就正确了。 如果:
-
+
其实,思路就是 通过 整体倒叙,把两段子串顺序颠倒,两个段子串里的的字符在倒叙一把,**负负得正**,这样就不影响子串里面字符的顺序了。
@@ -80,7 +80,7 @@ int main() {
可以的,不过,要记得 控制好 局部反转的长度,如果先局部反转,那么先反转的子串长度就是 len - n,如图:
-
+
代码如下:
diff --git "a/problems/kamacoder/0058.345円214円272円351円227円264円345円222円214円.md" "b/problems/kamacoder/0058.345円214円272円351円227円264円345円222円214円.md"
index 23e7189a15..b62adcfc62 100644
--- "a/problems/kamacoder/0058.345円214円272円351円227円264円345円222円214円.md"
+++ "b/problems/kamacoder/0058.345円214円272円351円227円264円345円222円214円.md"
@@ -93,7 +93,7 @@ int main() {
如图:
-
+
如果,我们想统计,在vec数组上 下标 2 到下标 5 之间的累加和,那是不是就用 p[5] - p[1] 就可以了。
@@ -109,7 +109,7 @@ int main() {
如图所示:
-
+
`p[5] - p[1]` 就是 红色部分的区间和。
@@ -357,3 +357,54 @@ int main(int argc, char *argv[])
```
+### Go
+
+```go
+package main
+
+import (
+ "fmt"
+ "bufio"
+ "strconv"
+ "os"
+)
+
+func main() {
+ // bufio中读取数据的接口,因为数据卡的比较严,导致使用fmt.Scan会超时
+ scanner := bufio.NewScanner(os.Stdin)
+
+ // 获取数组大小
+ scanner.Scan()
+ n, _ := strconv.Atoi(scanner.Text())
+
+ // 获取数组元素的同时计算前缀和,一般建议切片开大一点防止各种越界问题
+ arr := make([]int, n + 1)
+ for i := 0; i < n; i++ { + scanner.Scan() + arr[i], _ = strconv.Atoi(scanner.Text()) + if i != 0 { + arr[i] += arr[i - 1] + } + } + + /* + 区间[l, r]的和可以使用区间[0, r]和[0, l - 1]相减得到, + 在代码中即为arr[r]-arr[l-1]。这里需要注意l-1是否越界 + */ + for { + var l, r int + scanner.Scan() + _, err := fmt.Sscanf(scanner.Text(), "%d %d", &l, &r) + if err != nil { + return + } + + if l> 0 {
+ fmt.Println(arr[r] - arr[l - 1])
+ } else {
+ fmt.Println(arr[r])
+ }
+ }
+}
+```
+
diff --git "a/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I-SPFA.md" "b/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I-SPFA.md"
index 99986aaa2d..bebc2f39c5 100644
--- "a/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I-SPFA.md"
+++ "b/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I-SPFA.md"
@@ -62,7 +62,7 @@
给大家举一个例子:
-
+
本图中,对所有边进行松弛,真正有效的松弛,只有松弛 边(节点1->节点2) 和 边(节点1->节点3) 。
@@ -97,7 +97,7 @@
初始化,起点为节点1, 起点到起点的最短距离为0,所以minDist[1] 为 0。 将节点1 加入队列 (下次松弛从节点1开始)
-
+
------------
@@ -109,7 +109,7 @@
将节点2、节点3 加入队列,如图:
-
+
-----------------
@@ -124,7 +124,7 @@
将节点4,节点5 加入队列,如图:
-
+
--------------------
@@ -134,7 +134,7 @@
因为没有从节点3作为出发点的边,所以这里就从队列里取出节点3就好,不用做其他操作,如图:
-
+
------------
@@ -147,7 +147,7 @@
如图:
-
+
---------------
@@ -160,7 +160,7 @@
如图,将节点3加入队列,因为节点6已经在队列里,所以不用重复添加
-
+
所以我们在加入队列的过程可以有一个优化,**用visited数组记录已经在队列里的元素,已经在队列的元素不用重复加入**
@@ -174,7 +174,7 @@
所以直接从队列中取出,如图:
-
+
----------
@@ -264,7 +264,7 @@ int main() {
至于为什么 双向图且每一个节点和所有其他节点都相连的话,每个节点 都有 n-1 条指向该节点的边, 我再来举个例子,如图:
-[](https://code-thinking-1253855093.file.myqcloud.com/pics/20240416104138.png)
+
图中 每个节点都与其他所有节点相连,节点数n 为 4,每个节点都有3条指向该节点的边,即入度为3。
@@ -329,7 +329,7 @@ SPFA(队列优化版Bellman_ford) 在理论上 时间复杂度更胜一筹
如图:
-
+
正权回路 就是有环,但环的总权值为正数。
diff --git "a/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I.md" "b/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I.md"
index 2afc014b7e..fc79bcde1a 100644
--- "a/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I.md"
+++ "b/problems/kamacoder/0094.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円I.md"
@@ -46,7 +46,7 @@
1 3 5
```
-
+
## 思路
@@ -78,7 +78,7 @@
这里我给大家举一个例子,每条边有起点、终点和边的权值。例如一条边,节点A 到 节点B 权值为value,如图:
-
+
minDist[B] 表示 到达B节点 最小权值,minDist[B] 有哪些状态可以推出来?
@@ -127,7 +127,7 @@ if (minDist[B]> minDist[A] + value) minDist[B] = minDist[A] + value
如图:
-
+
其他节点对应的minDist初始化为max,因为我们要求最小距离,那么还没有计算过的节点 默认是一个最大数,这样才能更新最小距离。
@@ -150,36 +150,36 @@ if (minDist[B]> minDist[A] + value) minDist[B] = minDist[A] + value
边:节点5 -> 节点6,权值为-2 ,minDist[5] 还是默认数值max,所以不能基于 节点5 去更新节点6,如图:
-
+
(在复习一下,minDist[5] 表示起点到节点5的最短距离)
边:节点1 -> 节点2,权值为1 ,minDist[2]> minDist[1] + 1 ,更新 minDist[2] = minDist[1] + 1 = 0 + 1 = 1 ,如图:
-
+
边:节点5 -> 节点3,权值为1 ,minDist[5] 还是默认数值max,所以不能基于节点5去更新节点3 如图:
-
+
边:节点2 -> 节点5,权值为2 ,minDist[5]> minDist[2] + 2 (经过上面的计算minDist[2]已经不是默认值,而是 1),更新 minDist[5] = minDist[2] + 2 = 1 + 2 = 3 ,如图:
-
+
边:节点2 -> 节点4,权值为-3 ,minDist[4]> minDist[2] + (-3),更新 minDist[4] = minDist[2] + (-3) = 1 + (-3) = -2 ,如图:
-
+
边:节点4 -> 节点6,权值为4 ,minDist[6]> minDist[4] + 4,更新 minDist[6] = minDist[4] + 4 = -2 + 4 = 2
-
+
边:节点1 -> 节点3,权值为5 ,minDist[3]> minDist[1] + 5,更新 minDist[3] = minDist[1] + 5 = 0 + 5 = 5 ,如图:
-
+
--------
diff --git "a/problems/kamacoder/0095.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円II.md" "b/problems/kamacoder/0095.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円II.md"
index a3896b8896..f9cf8151b0 100644
--- "a/problems/kamacoder/0095.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円II.md"
+++ "b/problems/kamacoder/0095.345円237円216円345円270円202円351円227円264円350円264円247円347円211円251円350円277円220円350円276円223円II.md"
@@ -78,7 +78,7 @@ circle
我们拿题目中示例来画一个图:
-
+
图中 节点1 到 节点4 的最短路径是多少(题目中的最低运输成本) (注意边可以为负数的)
@@ -86,7 +86,7 @@ circle
而图中有负权回路:
-
+
那么我们在负权回路中多绕一圈,我们的最短路径 是不是就更小了 (也就是更低的运输成本)
@@ -183,7 +183,6 @@ struct Edge { //邻接表
Edge(int t, int w): to(t), val(w) {} // 构造函数
};
-
int main() {
int n, m, p1, p2, val;
cin>> n>> m;
@@ -229,16 +228,111 @@ int main() {
}
}
}
-
if (flag) cout << "circle" << endl; else if (minDist[end] == INT_MAX) { cout << "unconnected" << endl; } else { cout << minDist[end] << endl; } - } +``` + +以上代码看上去没问题,但提交之后会发现报错了,为什么呢? + +例如这组数据: + +``` +4 6 +1 4 3 +1 2 1 +1 3 1 +3 2 -2 +2 4 1 +3 4 0 +``` + +如图: + + + +上面代码在执行的过程中,节点4 已经出队列了,但 计算入度会反复计算 节点4的入度,导致 误判 该图有环。 + +我们需要记录哪些节点已经出队列了,哪些节点在队列里面,对于已经出队列的节点不用统计入度,以下为优化后的代码: + +```CPP +#include
+#include
> grid(n + 1); // 邻接表
+
+ // 将所有边保存起来
+ for(int i = 0; i < m; i++){ + cin>> p1>> p2>> val;
+ // p1 指向 p2,权值为 val
+ grid[p1].push_back(Edge(p2, val));
+ }
+ int start = 1; // 起点
+ int end = n; // 终点
+
+ vector