From 60d8274cc49a3b973e6dddb5b2fa3be87d7b9d94 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Mon, 8 Aug 2022 17:10:30 +0800 Subject: [PATCH 01/13] =?UTF-8?q?Update=200771.=20=E5=AE=9D=E7=9F=B3?= =?UTF-8?q?=E4=B8=8E=E7=9F=B3=E5=A4=B4.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...63344円270円216円347円237円263円345円244円264円.md" | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git "a/Solutions/0771. 345円256円235円347円237円263円344円270円216円347円237円263円345円244円264円.md" "b/Solutions/0771. 345円256円235円347円237円263円344円270円216円347円237円263円345円244円264円.md" index d1864f52..7d47c5cd 100644 --- "a/Solutions/0771. 345円256円235円347円237円263円344円270円216円347円237円263円345円244円264円.md" +++ "b/Solutions/0771. 345円256円235円347円237円263円344円270円216円347円237円263円345円244円264円.md" @@ -5,19 +5,40 @@ ## 题目大意 -给定一个字符串 `jewels` 代表石头中宝石的类型,再给定一个字符串 `stones` 代表你拥有的石头。`stones` 中每个字符代表了一种你拥有的石头的类型。 +**描述**:给定一个字符串 `jewels` 代表石头中宝石的类型,再给定一个字符串 `stones` 代表你拥有的石头。`stones` 中每个字符代表了一种你拥有的石头的类型。 -要求:计算出拥有的石头中有多少是宝石。 +**要求**:计算出拥有的石头中有多少是宝石。 -注意:字母区分大小写,因此 `a` 和 `A` 是不同类型的石头。 +**说明**: + +- 字母区分大小写,因此 `a` 和 `A` 是不同类型的石头。 +- 1ドル \le jewels.length, stones.length \le 50$。 +- `jewels` 和 `stones` 仅由英文字母组成。 +- `jewels` 中的所有字符都是唯一的。 + +**示例**: + +```Python +输入:jewels = "aA", stones = "aAAbbbb" +输出:3 + + +输入:jewels = "z", stones = "ZZ" +输出:0 +``` ## 解题思路 -用 `count` 来维护石头中的宝石个数。先使用哈希表或者集合存储宝石。再遍历数组 `stones`,并统计每块石头是否在哈希表中或集合中,如果在,则 `count += 1`,如果不在哈希表或集合中,则不统计。 +### 思路 1:哈希表 -最后输出答案 `count`。 +1. 用 `count` 来维护石头中的宝石个数。 +2. 先使用哈希表或者集合存储宝石。 +3. 再遍历数组 `stones`,并统计每块石头是否在哈希表中或集合中。 + 1. 如果当前石头在哈希表或集合中,则 `count += 1`。 + 2. 如果当前石头不在哈希表或集合中,则不统计。 +4. 最后返回 `count`。 -## 代码 +### 思路 1:代码 ```Python class Solution: @@ -32,3 +53,8 @@ class Solution: return count ``` +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(m + n),ドル其中 $m$ 是字符串 `jewels` 的长度,$n$ 是 `stones` 的长度。 +- **空间复杂度**:$O(m),ドル其中 $m$ 是字符串 `jewels` 的长度。 + From 006157d6fe88e283e5c39179e14ace95aae4985e Mon Sep 17 00:00:00 2001 From: ITCharge Date: Mon, 8 Aug 2022 17:10:39 +0800 Subject: [PATCH 02/13] =?UTF-8?q?Update=202235.=20=E4=B8=A4=E6=95=B4?= =?UTF-8?q?=E6=95=B0=E7=9B=B8=E5=8A=A0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...64346円225円260円347円233円270円345円212円240円.md" | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git "a/Solutions/2235. 344円270円244円346円225円264円346円225円260円347円233円270円345円212円240円.md" "b/Solutions/2235. 344円270円244円346円225円264円346円225円260円347円233円270円345円212円240円.md" index 2965832d..b4ba4503 100644 --- "a/Solutions/2235. 344円270円244円346円225円264円346円225円260円347円233円270円345円212円240円.md" +++ "b/Solutions/2235. 344円270円244円346円225円264円346円225円260円347円233円270円345円212円240円.md" @@ -29,32 +29,19 @@ ## 解题思路 -### 思路 1: - +### 思路 1:直接计算 +1. 直接计算整数 `num1` 与 `num2` 的和,返回 `num1 + num2` 即可。 ### 思路 1:代码 ```Python - +class Solution: + def sum(self, num1: int, num2: int) -> int: + return num1 + num2 ``` ### 思路 1:复杂度分析 -- **时间复杂度**: -- **空间复杂度**: - -### 思路 2: - - - -### 思路 2:代码 - -```Python - -``` - -### 思路 2:复杂度分析 - -- **时间复杂度**: -- **空间复杂度**: \ No newline at end of file +- **时间复杂度**:$O(1)$。 +- **空间复杂度**:$O(1)$。 From ea71e33f3a406d55c02e5931ba68f3f4212abd24 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Mon, 8 Aug 2022 17:10:54 +0800 Subject: [PATCH 03/13] =?UTF-8?q?Update=201929.=20=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E4=B8=B2=E8=81=94.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60347円273円204円344円270円262円350円201円224円.md" | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git "a/Solutions/1929. 346円225円260円347円273円204円344円270円262円350円201円224円.md" "b/Solutions/1929. 346円225円260円347円273円204円344円270円262円350円201円224円.md" index 7739606a..45172aec 100644 --- "a/Solutions/1929. 346円225円260円347円273円204円344円270円262円350円201円224円.md" +++ "b/Solutions/1929. 346円225円260円347円273円204円344円270円262円350円201円224円.md" @@ -5,24 +5,46 @@ ## 题目大意 -给你一个长度为 `n` 的整数数组 `nums`。 +**描述**:给定一个长度为 `n` 的整数数组 `nums`。 -要求:构建一个长度为 `2 * n` 的答案数组 `ans`,数组下标从 `0` 开始计数 ,对于所有 `0 <= i < n` 的 `i` ,满足下述所有要求: +**要求**:构建一个长度为 `2 * n` 的答案数组 `ans`,答案数组下标从 `0` 开始计数 ,对于所有 `0 <= i < n` 的 `i` ,满足下述所有要求: - `ans[i] == nums[i]`。 - `ans[i + n] == nums[i]`。 -具体而言,`ans` 由两个 `nums` 数组串联形成。最后返回数组 `ans` 。 +具体而言,`ans` 由两个 `nums` 数组「串联」形成。 -## 解题思路 +**说明**: + +- $n == nums.length$。 +- 1ドル \le n \le 1000$。 +- 1ドル \le nums[i] \le 1000$。 + +**示例**: + +```Python +输入:nums = [1,2,1] +输出:[1,2,1,1,2,1] +解释:数组 ans 按下述方式形成: +- ans = [nums[0],nums[1],nums[2],nums[0],nums[1],nums[2]] +- ans = [1,2,1,1,2,1] + + +输入:nums = [1,3,2,1] +输出:[1,3,2,1,1,3,2,1] +解释:数组 ans 按下述方式形成: +- ans = [nums[0],nums[1],nums[2],nums[3],nums[0],nums[1],nums[2],nums[3]] +- ans = [1,3,2,1,1,3,2,1] +``` -使用 `ans` 作为答案数组。然后按顺序遍历两次数组 `nums` 中的元素,并依次添加到 `ans` 的尾部。最后返回 `ans`。 +## 解题思路 -其实,`Python` 中更快速的做法是 `return nums + nums`。 +### 思路 1:按要求模拟 -## 代码 +1. 定义一个数组变量(列表)`ans` 作为答案数组。 +2. 然后按顺序遍历两次数组 `nums` 中的元素,并依次添加到 `ans` 的尾部。最后返回 `ans`。 -### 思路 1: +### 思路 1:代码 ```Python class Solution: @@ -35,7 +57,16 @@ class Solution: return ans ``` -### 思路 2: +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n),ドル其中 $n$ 为数组 `nums` 的长度。 +- **空间复杂度**:$O(n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(n)$。不算上则空间复杂度为 $O(1)$。 + +### 思路 2:利用运算符 + +`Python` 中可以直接利用 `+` 号运算符将两个列表快速进行串联。即 `return nums + nums`。 + +### 思路 2:代码 ```Python class Solution: @@ -43,3 +74,7 @@ class Solution: return nums + nums ``` +### 思路 2:复杂度分析 + +- **时间复杂度**:$O(n),ドル其中 $n$ 为数组 `nums` 的长度。 +- **空间复杂度**:$O(n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(n)$。不算上则空间复杂度为 $O(1)$。 From 774639b392417bb53bc7b44844fd088e5f6754d5 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 09:29:35 +0800 Subject: [PATCH 04/13] =?UTF-8?q?Update=201480.=20=E4=B8=80=E7=BB=B4?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E7=9A=84=E5=8A=A8=E6=80=81=E5=92=8C.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04345円212円250円346円200円201円345円222円214円.md" | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git "a/Solutions/1480. 344円270円200円347円273円264円346円225円260円347円273円204円347円232円204円345円212円250円346円200円201円345円222円214円.md" "b/Solutions/1480. 344円270円200円347円273円264円346円225円260円347円273円204円347円232円204円345円212円250円346円200円201円345円222円214円.md" index 3d10cdad..8ffe601e 100644 --- "a/Solutions/1480. 344円270円200円347円273円264円346円225円260円347円273円204円347円232円204円345円212円250円346円200円201円345円222円214円.md" +++ "b/Solutions/1480. 344円270円200円347円273円264円346円225円260円347円273円204円347円232円204円345円212円250円346円200円201円345円222円214円.md" @@ -5,24 +5,59 @@ ## 题目大意 -给定一个数组 nums,返回前缀合数组。 +**描述**:给定一个数组 `nums`。 + +**要求**:返回数组 `nums` 的动态和。 + +**说明**: + +- **动态和**:数组前 `i` 项元素和构成的数组,计算公式为 `runningSum[i] = sum(nums[0] ... nums[i])`。 + +**示例**: + +```Python +输入:nums = [1,2,3,4] +输出:[1,3,6,10] +解释:动态和计算过程为 [1, 1+2, 1+2+3, 1+2+3+4]。 + + +输入:nums = [1,1,1,1,1] +输出:[1,2,3,4,5] +解释:动态和计算过程为 [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1]。 +``` ## 解题思路 -新建数组,递推即可。 +### 思路 1:递推 + +根据动态和的公式 `runningSum[i] = sum(nums[0] ... nums[i])`,可以推导出: + +$runningSum = \begin{cases} nums[0], & i = 0 \cr runningSum[i - 1] + nums[i], & i> 0\end{cases}$ + +则解决过程如下: -## 代码 +1. 新建一个长度等于 `nums` 的数组 `res` 用于存放答案。 +2. 初始化 `res[0] = nums[0]`。 +3. 从下标 `1` 开始遍历数组 `nums`,递推更新 `res[i] = res[i - 1] + nums[i]`。 +4. 遍历结束,返回 `res` 作为答案。 + +### 思路 1:代码 ```Python class Solution: def runningSum(self, nums: List[int]) -> List[int]: - n = len(nums) - dp = [0 for _ in range(n)] - for i in range(n): + size = len(nums) + res = [0 for _ in range(size)] + for i in range(size): if i == 0: - dp[i] = nums[i] + res[i] = nums[i] else: - dp[i] = dp[i-1] + nums[i] - return dp + res[i] = res[i - 1] + nums[i] + return res ``` +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n)$。一重循环遍历的时间复杂度为 $O(n)$。 +- **空间复杂度**:$O(n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(n)$。不算上则空间复杂度为 $O(1)$。 + From 07af991e6d5ff0e3b52b977b403c6ac8be50929e Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 10:02:58 +0800 Subject: [PATCH 05/13] =?UTF-8?q?Create=200709.=20=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=88=90=E5=B0=8F=E5=86=99=E5=AD=97=E6=AF=8D.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...17345円206円231円345円255円227円346円257円215円.md" | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 "Solutions/0709. 350円275円254円346円215円242円346円210円220円345円260円217円345円206円231円345円255円227円346円257円215円.md" diff --git "a/Solutions/0709. 350円275円254円346円215円242円346円210円220円345円260円217円345円206円231円345円255円227円346円257円215円.md" "b/Solutions/0709. 350円275円254円346円215円242円346円210円220円345円260円217円345円206円231円345円255円227円346円257円215円.md" new file mode 100644 index 00000000..ca827697 --- /dev/null +++ "b/Solutions/0709. 350円275円254円346円215円242円346円210円220円345円260円217円345円206円231円345円255円227円346円257円215円.md" @@ -0,0 +1,77 @@ +# [0709. 转换成小写字母](https://leetcode.cn/problems/to-lower-case/) + +- 标签:字符串 +- 难度:简单 + +## 题目大意 + +**描述**:给定一个字符串 `s`。 + +**要求**:将该字符串中的大写字母转换成相同的小写字母,返回新的字符串。 + +**说明**: + +- 1ドル \le s.length \le 100$。 +- `s` 由 ASCII 字符集中的可打印字符组成。 + +**示例**: + +```Python +输入:s = "Hello" +输出:"hello" + + +输入:s = "LOVELY" +输出:"lovely" +``` + +## 解题思路 + +### 思路 1:直接模拟 + +- 大写字母 `A` ~ `Z` 的 ASCII 码范围为 `[65, 90]`。 +- 小写字母 `a` ~ `z` 的 ASCII 码范围为 `[97, 122]`。 + +将大写字母的 ASCII 码加 `32`,就得到了对应的小写字母,则解决步骤如下: + +1. 使用一个字符串变量 `ans` 存储最终答案字符串。 +2. 遍历字符串 `s`,对于当前字符 `ch`: + 1. 如果 `ch` 的 ASCII 码范围在 `[65, 90]`,则说明 `ch` 为大写字母。将 `ch` 的 ASCII 码增加 `32`,再转换为对应的字符,存入字符串 `ans` 的末尾。 + 2. 如果 `ch` 的 ASCII 码范围不在 `[65, 90]`,则说明 `ch` 为小写字母。直接将 `ch` 存入字符串 `ans` 的末尾。 +3. 遍历完字符串 `s`,返回答案字符串 `ans`。 + +### 思路 1:代码 + +```Python +class Solution: + def toLowerCase(self, s: str) -> str: + ans = "" + for ch in s: + if ord('A') <= ord(ch) <= ord('Z'): + ans += chr(ord(ch) + 32) + else: + ans += ch + return ans +``` + +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n)$。一重循环遍历的时间复杂度为 $O(n)$。 +- **空间复杂度**:$O(n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(n)$。不算上则空间复杂度为 $O(1)$。 + +### 思路 2:使用 API + +`Python` 语言中自带大写字母转小写字母的 API:`lower()`,用 API 转换完成之后,直接返回新的字符串。 + +### 思路 2:代码 + +```Python +class Solution: + def toLowerCase(self, s: str) -> str: + return s.lower() +``` + +### 思路 2:复杂度分析 + +- **时间复杂度**:$O(n)$。一重循环遍历的时间复杂度为 $O(n)$。 +- **空间复杂度**:$O(n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(n)$。不算上则空间复杂度为 $O(1)$。 \ No newline at end of file From 3c66bb9bc75bfdd12aa3869bcf0b28123811553c Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 11:01:56 +0800 Subject: [PATCH 06/13] =?UTF-8?q?Create=201672.=20=E6=9C=80=E5=AF=8C?= =?UTF-8?q?=E6=9C=89=E5=AE=A2=E6=88=B7=E7=9A=84=E8=B5=84=E4=BA=A7=E6=80=BB?= =?UTF-8?q?=E9=87=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04344円272円247円346円200円273円351円207円217円.md" | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 "Solutions/1672. 346円234円200円345円257円214円346円234円211円345円256円242円346円210円267円347円232円204円350円265円204円344円272円247円346円200円273円351円207円217円.md" diff --git "a/Solutions/1672. 346円234円200円345円257円214円346円234円211円345円256円242円346円210円267円347円232円204円350円265円204円344円272円247円346円200円273円351円207円217円.md" "b/Solutions/1672. 346円234円200円345円257円214円346円234円211円345円256円242円346円210円267円347円232円204円350円265円204円344円272円247円346円200円273円351円207円217円.md" new file mode 100644 index 00000000..7d93fe03 --- /dev/null +++ "b/Solutions/1672. 346円234円200円345円257円214円346円234円211円345円256円242円346円210円267円347円232円204円350円265円204円344円272円247円346円200円273円351円207円217円.md" @@ -0,0 +1,68 @@ +# [1672. 最富有客户的资产总量](https://leetcode.cn/problems/richest-customer-wealth/) + +- 标签:数组、矩阵 +- 难度:简单 + +## 题目大意 + +**描述**:给定一个 `m x n` 的整数网格 `accounts`,其中 `accounts[i][j]` 是第 `i` 位客户在第 `j` 家银行托管的资产数量。 + +**要求**:返回最富有客户所拥有的资产总量。 + +**说明**: + +- 客户的资产总量:指的是他们在各家银行托管的资产数量之和。 +- 最富有客户:资产总量最大的客户。 +- $m == accounts.length$。 +- $n == accounts[i].length$。 +- 1ドル \le m, n \le 50$。 +- 1ドル \le accounts[i][j] \le 100$。 + +**示例**: + +```Python +输入:accounts = [[1,2,3],[3,2,1]] +输出:6 +解释: +第 1 位客户的资产总量 = 1 + 2 + 3 = 6 +第 2 位客户的资产总量 = 3 + 2 + 1 = 6 +两位客户都是最富有的,资产总量都是 6 ,所以返回 6。 + + +输入:accounts = [[1,5],[7,3],[3,5]] +输出:10 +解释: +第 1 位客户的资产总量 = 6 +第 2 位客户的资产总量 = 10 +第 3 位客户的资产总量 = 8 +第 2 位客户是最富有的,资产总量是 10,随意返回 10。 +``` + +## 解题思路 + +### 思路 1:直接模拟 + +1. 使用变量 `max_ans` 存储最富有客户所拥有的资产总量。 +2. 遍历所有客户,对于当前客户 `accounts[i]`,统计其拥有的资产总量。 +3. 将当前客户的资产总量与 `max_ans` 进行比较,如果大于 `max_ans`,则更新 `max_ans` 的值。 +4. 遍历完所有客户,最终返回 `max_ans` 作为结果。 + +### 思路 1:代码 + +```Python +class Solution: + def maximumWealth(self, accounts: List[List[int]]) -> int: + max_ans = 0 + for i in range(len(accounts)): + total = 0 + for j in range(len(accounts[i])): + total += accounts[i][j] + if total> max_ans: + max_ans = total + return max_ans +``` + +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(m * n)$。其中 $m$ 和 $n$ 分别为二维数组 $accounts$ 的行数和列数。两重循环遍历的时间复杂度为 $O(m * n)$ 。 +- **空间复杂度**:$O(1)$。 From cf383a0b6780189ff4d06fb9c29b1dc2c0894758 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 13:54:32 +0800 Subject: [PATCH 07/13] =?UTF-8?q?Update=200066.=20=E5=8A=A0=E4=B8=80.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Solutions/0066. 345円212円240円344円270円200円.md" | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git "a/Solutions/0066. 345円212円240円344円270円200円.md" "b/Solutions/0066. 345円212円240円344円270円200円.md" index 3bed6551..412177b1 100644 --- "a/Solutions/0066. 345円212円240円344円270円200円.md" +++ "b/Solutions/0066. 345円212円240円344円270円200円.md" @@ -35,24 +35,29 @@ 1. 数组前补 `0` 位。 2. 将个位数字进行加 `1` 计算。 3. 遍历数组 - 1. 如果该位数字 大于等于 `10`,则向下一位进 `1`,继续下一位判断进位。 + 1. 如果该位数字大于等于 `10`,则向下一位进 `1`,继续下一位判断进位。 2. 如果该位数字小于 `10`,则跳出循环。 -### 思路 1:模拟代码 +### 思路 1:代码 ```Python def plusOne(self, digits: List[int]) -> List[int]: digits = [0] + digits - digits[len(digits)-1] += 1 - for i in range(len(digits)-1,0,-1): + digits[len(digits) - 1] += 1 + for i in range(len(digits)-1, 0, -1): if digits[i] != 10: break else: digits[i] = 0 - digits[i-1] += 1 + digits[i - 1] += 1 if digits[0] == 0: return digits[1:] else: return digits -``` \ No newline at end of file +``` + +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n)$。一重循环遍历的时间复杂度为 $O(n)$ 。 +- **空间复杂度**:$O(1)$。 \ No newline at end of file From 9a7f2dce02f84b45fd6b2204e3a3f5f4ba9e5785 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 13:54:35 +0800 Subject: [PATCH 08/13] =?UTF-8?q?Update=200189.=20=E8=BD=AE=E8=BD=AC?= =?UTF-8?q?=E6=95=B0=E7=BB=84.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...89. 350円275円256円350円275円254円346円225円260円347円273円204円.md" | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git "a/Solutions/0189. 350円275円256円350円275円254円346円225円260円347円273円204円.md" "b/Solutions/0189. 350円275円256円350円275円254円346円225円260円347円273円204円.md" index 10f5c1a9..bca4fa34 100644 --- "a/Solutions/0189. 350円275円256円350円275円254円346円225円260円347円273円204円.md" +++ "b/Solutions/0189. 350円275円256円350円275円254円346円225円260円347円273円204円.md" @@ -29,7 +29,7 @@ ## 解题思路 -### 思路 1: +### 思路 1: 数组翻转 可以用一个新数组,先保存原数组的后 `k` 个元素,再保存原数组的前 `n - k` 个元素。但题目要求不使用额外的数组空间,那么就需要在原数组上做操作。 @@ -60,3 +60,7 @@ class Solution: right -= 1https://lestore.lenovo.com/detail/25113 ``` +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n)$。翻转的时间复杂度为 $O(n)$ 。 +- **空间复杂度**:$O(1)$。 \ No newline at end of file From 26b605fec27f09c08decfd45584259026c093a99 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 13:54:44 +0800 Subject: [PATCH 09/13] =?UTF-8?q?Update=200048.=20=E6=97=8B=E8=BD=AC?= =?UTF-8?q?=E5=9B=BE=E5=83=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13350円275円254円345円233円276円345円203円217円.md" | 71 +++++++++++++++---- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git "a/Solutions/0048. 346円227円213円350円275円254円345円233円276円345円203円217円.md" "b/Solutions/0048. 346円227円213円350円275円254円345円233円276円345円203円217円.md" index 5acd7282..6bb4928d 100644 --- "a/Solutions/0048. 346円227円213円350円275円254円345円233円276円345円203円217円.md" +++ "b/Solutions/0048. 346円227円213円350円275円254円345円233円276円345円203円217円.md" @@ -5,40 +5,87 @@ ## 题目大意 -给定一个 n*n 的二维矩阵(代表图像)。将二维矩阵顺时针旋转 90°,要求不能使用额外的数组空间。 +**描述**:给定一个 `n * n` 大小的二维矩阵(代表图像)`matrix`。 + +**要求**:将二维矩阵 `matrix` 顺时针旋转 90°。 + +**说明**: + +- 不能使用额外的数组空间。 +- $n == matrix.length == matrix[i].length$。 +- 1ドル \le n \le 20$。 +- $-1000 \le matrix[i][j] \le 1000$。 + +**示例**: + +```Python +输入:matrix = [[1,2,3],[4,5,6],[7,8,9]] +输出:[[7,4,1],[8,5,2],[9,6,3]] +``` + +![](https://assets.leetcode.com/uploads/2020/08/28/mat1.jpg) + +```Python +输入:matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] +输出:[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]] +``` + +![](https://assets.leetcode.com/uploads/2020/08/28/mat2.jpg) ## 解题思路 +### 思路 1:原地旋转 + 如果使用额外数组空间的话,将对应元素存放到对应位置即可。如果不使用额外的数组空间,则需要观察每一个位置上的点最初位置和最终位置有什么规律。 -对于矩阵中第 i 行的第 j 个元素,在旋转后,它出现在倒数第 i 列的第 j 个位置。即 +对于矩阵中第 `i` 行的第 `j` 个元素,在旋转后,它出现在倒数第 `i` 列的第 `j` 个位置。即 `matrixnew[j][n − i − 1] = matrix[i][j]`。 -`matrixnew[col][n−row−1] = matrix[row][col]` +而 `matrixnew[j][n - i - 1]` 的点经过旋转移动到了 `matrix[n − i − 1][n − j − 1]` 的位置。 -而 `matrixnew[col][n-row-1]` 的点经过旋转移动到了 `matrix[n−row−1][n−col−1]` 的位置。 +`matrix[n − i − 1][n − j − 1]` 位置上的点经过旋转移动到了 `matrix[n − j − 1][i]` 的位置。 -`matrix[n−row−1][n−col−1]` 位置上的点经过旋转移动到了 `matrix[n−col−1][row]` 的位置。 +`matrix[n− j − 1][i]` 位置上的点经过旋转移动到了最初的 `matrix[i][j]` 的位置。 -`matrix[n−col−1][row]` 位置上的点经过旋转移动到了最初的 `matrix[row][col]` 的位置。 +这样就形成了一个循环,我们只需要通过一个临时变量 `temp` 就可以将循环中的元素逐一进行交换。`Python` 中则可以直接使用语法直接交换。 -这样就形成了一个循环,我们只需要通过一个临时变量 tmp 就可以将循环中的点逐一进行交换。 +### 思路 1:代码 +```Python +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + n = len(matrix) + for i in range(n // 2): + for j in range((n + 1) // 2): + matrix[i][j], matrix[n - j - 1][i], matrix[n - i - 1][n - j - 1], matrix[j][n - i - 1] = matrix[n - j - 1][i], matrix[n - i - 1][n - j - 1], matrix[j][n - i - 1], matrix[i][j] +``` -另一种思路是利用翻转代替旋转。 +### 思路 1:复杂度分析 -原矩阵可以通过一次水平翻转+主对角线翻转得到旋转后的二维矩阵。具体可以参考代码。 +- **时间复杂度**:$O(n^2)$。 +- **空间复杂度**:$O(1)$。 -## 代码 +### 思路 2:原地翻转 + +通过观察可以得出:原矩阵可以通过一次「水平翻转」+「主对角线翻转」得到旋转后的二维矩阵。 + +### 思路 2:代码 ```Python def rotate(self, matrix: List[List[int]]) -> None: n = len(matrix) - for i in range(n//2): + + for i in range(n // 2): for j in range(n): - matrix[i][j], matrix[n-i-1][j] = matrix[n-i-1][j], matrix[i][j] + matrix[i][j], matrix[n - i - 1][j] = matrix[n - i - 1][j], matrix[i][j] + for i in range(n): for j in range(i): matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` +### 思路 2:复杂度分析 + +- **时间复杂度**:$O(n^2)$。 +- **空间复杂度**:$O(1)$。 + From efdb7d2288b4b638744cf181d23e13a3e30307b8 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 13:54:48 +0800 Subject: [PATCH 10/13] =?UTF-8?q?Update=200724.=20=E5=AF=BB=E6=89=BE?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E7=9A=84=E4=B8=AD=E5=BF=83=E4=B8=8B=E6=A0=87?= =?UTF-8?q?.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...204344円270円255円345円277円203円344円270円213円346円240円207円.md" | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git "a/Solutions/0724. 345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円344円270円213円346円240円207円.md" "b/Solutions/0724. 345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円344円270円213円346円240円207円.md" index b4cf95c9..a8c8dfce 100644 --- "a/Solutions/0724. 345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円344円270円213円346円240円207円.md" +++ "b/Solutions/0724. 345円257円273円346円211円276円346円225円260円347円273円204円347円232円204円344円270円255円345円277円203円344円270円213円346円240円207円.md" @@ -31,7 +31,7 @@ 两次遍历,第一次遍历先求出数组全部元素和。第二次遍历找到左侧元素和恰好为全部元素和一半的位置。 -### 思路 1:两次遍历代码 +### 思路 1:代码 ```Python class Solution: @@ -47,3 +47,8 @@ class Solution: return -1 ``` +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n)$。两次遍历的时间复杂度为 $O(2 * n)$ ,$O(2 * n) == O(n)$。 +- **空间复杂度**:$O(1)$。 + From bb0011384994d8d9b3278b0b8ead8694c6e559da Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 14:01:24 +0800 Subject: [PATCH 11/13] =?UTF-8?q?Update=200054.=20=E8=9E=BA=E6=97=8B?= =?UTF-8?q?=E7=9F=A9=E9=98=B5.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...72346円227円213円347円237円251円351円230円265円.md" | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git "a/Solutions/0054. 350円236円272円346円227円213円347円237円251円351円230円265円.md" "b/Solutions/0054. 350円236円272円346円227円213円347円237円251円351円230円265円.md" index 3de2b98c..45343ec4 100644 --- "a/Solutions/0054. 350円236円272円346円227円213円347円237円251円351円230円265円.md" +++ "b/Solutions/0054. 350円236円272円346円227円213円347円237円251円351円230円265円.md" @@ -5,15 +5,43 @@ ## 题目大意 -给定一个 m * n 大小的二维矩阵 matrix。要求按照顺时针旋转的顺序,返回矩阵中的所有元素。 +**描述**:给定一个 `m * n` 大小的二维矩阵 `matrix`。 + +**要求**:按照顺时针旋转的顺序,返回矩阵中的所有元素。 + +**说明**: + +- $m == matrix.length$。 +- $n == matrix[i].length$。 +- 1ドル \le m, n \le 10$。 +- $-100 \le matrix[i][j] \le 100$。 + +**示例**: + +```Python +输入:matrix = [[1,2,3],[4,5,6],[7,8,9]] +输出:[1,2,3,6,9,8,7,4,5] +``` + +![](https://assets.leetcode.com/uploads/2020/11/13/spiral1.jpg) + +```Python +输入:matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] +输出:[1,2,3,4,8,12,11,10,9,5,6,7] +``` + +![](https://assets.leetcode.com/uploads/2020/11/13/spiral.jpg) ## 解题思路 -按照题意进行模拟。可以实现定义一下上、下、左、右的边界,然后按照逆时针的顺序从边界上依次访问元素。 +### 思路 1:模拟 -当访问完当前边界之后,要更新一下边界位置,缩小范围,方便下一轮进行访问。 +1. 使用数组 `ans` 存储答案。然后定义一下上、下、左、右的边界。 +2. 然后按照逆时针的顺序从边界上依次访问元素。 +3. 当访问完当前边界之后,要更新一下边界位置,缩小范围,方便下一轮进行访问。 +4. 最后返回答案数组 `ans`。 -## 代码 +### 思路 1:代码 ```Python class Solution: @@ -44,3 +72,8 @@ class Solution: return ans ``` +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(m * n)$。其中 $m$、$n$ 分别为二维矩阵的行数和列数。 +- **空间复杂度**:$O(m * n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(m * n)$。不算上则空间复杂度为 $O(1)$。 + From 75279ea55781e68feff73805d8488b297a8e48ea Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 14:19:47 +0800 Subject: [PATCH 12/13] =?UTF-8?q?Update=200498.=20=E5=AF=B9=E8=A7=92?= =?UTF-8?q?=E7=BA=BF=E9=81=8D=E5=8E=86.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...22347円272円277円351円201円215円345円216円206円.md" | 50 ++++++++++++++----- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git "a/Solutions/0498. 345円257円271円350円247円222円347円272円277円351円201円215円345円216円206円.md" "b/Solutions/0498. 345円257円271円350円247円222円347円272円277円351円201円215円345円216円206円.md" index 24acbd52..688d4df3 100644 --- "a/Solutions/0498. 345円257円271円350円247円222円347円272円277円351円201円215円345円216円206円.md" +++ "b/Solutions/0498. 345円257円271円350円247円222円347円272円277円351円201円215円345円216円206円.md" @@ -5,31 +5,50 @@ ## 题目大意 -给你一个大小为 `m * n` 的矩阵 `mat` 。 +**描述**:给定一个大小为 `m * n` 的矩阵 `mat` 。 -要求:以对角线遍历的顺序,用一个数组返回这个矩阵中的所有元素。 +**要求**:以对角线遍历的顺序,用一个数组返回这个矩阵中的所有元素。 + +**说明**: + +- $m == mat.length$。 +- $n == mat[i].length$。 +- 1ドル \le m, n \le 10^4$。 +- 1ドル \le m * n \le 10^4$。 +- $-10^5 \le mat[i][j] \le 10^5$。 + +**示例**: + +```Python +输入:mat = [[1,2,3],[4,5,6],[7,8,9]] +输出:[1,2,4,7,5,3,6,8,9] +``` + +![](https://assets.leetcode.com/uploads/2021/04/10/diag1-grid.jpg) ## 解题思路 +### 思路 1:找规律 + 考虑边界问题 + 这道题的关键是「找规律」和「考虑边界问题」。 找规律: -- 当行号 + 列号为偶数时,遍历方向为从左下到右上。可以记为右上方向(-1, +1),即行号 -1,列号 +1。 -- 当行号 + 列号为奇数时,遍历方向为从右上到左下。可以记为左下方向(+1, -1),即行号 +1,列号 -1。 +1. 当「行号 + 列号」为偶数时,遍历方向为从左下到右上。可以记为右上方向 `(-1, +1)`,即行号减 `1`,列号加 `1`。 +2. 当「行号 + 列号」为奇数时,遍历方向为从右上到左下。可以记为左下方向 `(+1, -1)`,即行号加 `1`,列号减 `1`。 边界情况: -- 向右上方向移动时: - - 如果在最后一列,则向下方移动,即 `x += 1`。 - - 如果在第一行,则向右方移动,即 `y += 1`。 - - 其余情况想右上方向移动,即 `x -= 1`、`y += 1`。 -- 向左下方向移动时: - - 如果在最后一行,则向右方移动,即 `y += 1`。 - - 如果在第一列,则向下方移动,即 `x += 1`。 - - 其余情况向左下方向移动,即 `x += 1`、`y -= 1`。 +1. 向右上方向移动时: + 1. 如果在最后一列,则向下方移动,即 `x += 1`。 + 2. 如果在第一行,则向右方移动,即 `y += 1`。 + 3. 其余情况想右上方向移动,即 `x -= 1`、`y += 1`。 +2. 向左下方向移动时: + 1. 如果在最后一行,则向右方移动,即 `y += 1`。 + 2. 如果在第一列,则向下方移动,即 `x += 1`。 + 3. 其余情况向左下方向移动,即 `x += 1`、`y -= 1`。 -## 代码 +### 思路 1:代码 ```Python class Solution: @@ -68,6 +87,11 @@ class Solution: return ans ``` +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(m \times n)$。其中 $m$、$n$ 分别为二维矩阵的行数、列数。 +- **空间复杂度**:$O(m * n)$。如果算上答案数组的空间占用,则空间复杂度为 $O(m * n)$。不算上则空间复杂度为 $O(1)$。 + ## 参考资料 - 【题解】[「498. 对角线遍历」最简单易懂! - 对角线遍历 - 力扣(LeetCode)](https://leetcode.cn/problems/diagonal-traverse/solution/498-dui-jiao-xian-bian-li-zui-jian-dan-y-ibu3/) From 7aacbc38a4275feb9dbcbce76f2be84d08e70b84 Mon Sep 17 00:00:00 2001 From: ITCharge Date: Tue, 9 Aug 2022 14:36:01 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=8CLeetcode=20?= =?UTF-8?q?=E5=88=B7=E9=A2=98=E8=AF=BE=E7=A8=8B=E7=AC=AC=E4=B8=80=E6=9C=9F?= =?UTF-8?q?=E3=80=8D=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Course/Course-Git-01.md | 61 ++++++++++++++++++---------------- Assets/Course/Course-Web-01.md | 60 +++++++++++++++++---------------- 2 files changed, 65 insertions(+), 56 deletions(-) diff --git a/Assets/Course/Course-Git-01.md b/Assets/Course/Course-Git-01.md index bf23f895..d2749100 100644 --- a/Assets/Course/Course-Git-01.md +++ b/Assets/Course/Course-Git-01.md @@ -1,4 +1,4 @@ -# Leetcode 刷题课程第一期 +# Leetcode 刷题课程第 1 期:算法入门与数组篇 ## 课程信息 @@ -9,7 +9,7 @@ ## 课程大纲 -### Task 00:熟悉规则(1 天) +### Task 00:熟悉规则( 1 天) - 组队、修改群昵称。 - 熟悉打卡规则。 @@ -17,9 +17,9 @@ --- -### Task 01:数据结构与算法简介、LeetCode 入门及攻略(2 天) +### Task 01:数据结构与算法简介、LeetCode 入门及攻略(第 01 ~ 02 天) -- 第 01 天学习内容: +- 第 01 ~ 02 天学习内容: - [数据结构与算法](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/00.Introduction/01.Data-Structures-Algorithms.md) - [算法复杂度](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/00.Introduction/02.Algorithm-Complexity.md) - [LeetCode 入门与攻略](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/00.Introduction/03.LeetCode-Guide.md) @@ -27,18 +27,23 @@ - [2235. 两整数相加](https://leetcode.cn/problems/add-two-integers/) - [1929. 数组串联](https://leetcode.cn/problems/concatenation-of-array/) - [0771. 宝石与石头](https://leetcode.cn/problems/jewels-and-stones/) +- 第 02 天课程题目列表: + - [1480. 一维数组的动态和](https://leetcode.cn/problems/running-sum-of-1d-array/) + - [0709. 转换成小写字母](https://leetcode.cn/problems/to-lower-case/) + - [1672. 最富有客户的资产总量](https://leetcode.cn/problems/richest-customer-wealth/) + --- -### Task 02:数组基础(2 天) +### Task 02:数组基础(第 03 ~ 04 天) -- 第 02 ~ 03 天学习内容: +- 第 03 ~ 04 天学习内容: - [数组基础知识](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/01.Array-Basic/01.Array-Basic.md) -- 第 02 天课程题目: +- 第 03 天课程题目: - [0066. 加一](https://leetcode.cn/problems/plus-one/) - [0724. 寻找数组的中心下标](https://leetcode.cn/problems/find-pivot-index/) - [0189. 旋转数组](https://leetcode.cn/problems/rotate-array/) -- 第 03 天课程题目: +- 第 04 天课程题目: - [0048. 旋转图像](https://leetcode.cn/problems/rotate-image/) - [0054. 螺旋矩阵](https://leetcode.cn/problems/spiral-matrix/) - [0498. 对角线遍历](https://leetcode.cn/problems/diagonal-traverse/) @@ -46,29 +51,29 @@ --- -### Task 03 数组排序(4 天) +### Task 03 数组排序(第 05 ~ 08 天) -- 第 04 天学习内容: +- 第 05 天学习内容: - [冒泡排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/01.Array-Bubble-Sort.md)、[选择排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/02.Array-Selection-Sort.md)、[插入排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/03.Array-Insertion-Sort.md) -- 第 04 天课程题目: +- 第 05 天课程题目: - [剑指 Offer 45. 把数组排成最小的数](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) - [0283. 移动零](https://leetcode.cn/problems/move-zeroes/) - [0912. 排序数组](https://leetcode.cn/problems/sort-an-array/) -- 第 05 天学习内容: +- 第 06 天学习内容: - [归并排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/05.Array-Merge-Sort.md)、[希尔排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/04.Array-Shell-Sort.md) -- 第 05 天课程题目: +- 第 06 天课程题目: - [0506. 相对名次](https://leetcode.cn/problems/relative-ranks/) - [面试题 10.01. 合并排序的数组](https://leetcode.cn/problems/sorted-merge-lcci/) - [剑指 Offer 51. 数组中的逆序对](https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) -- 第 06 天学习内容: +- 第 07 天学习内容: - [快速排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/06.Array-Quick-Sort.md)、[堆排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/07.Array-Heap-Sort.md) -- 第 06 天课程题目: +- 第 07 天课程题目: - [0075. 颜色分类](https://leetcode.cn/problems/sort-colors/) - [0215. 数组中的第K个最大元素](https://leetcode.cn/problems/kth-largest-element-in-an-array/) - [剑指 Offer 40. 最小的k个数](https://leetcode.cn/problems/zui-xiao-de-kge-shu-lcof/) -- 第 07 天学习内容: +- 第 08 天学习内容: - [计数排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/08.Array-Counting-Sort.md)、[桶排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/09.Array-Bucket-Sort.md)、[基数排序](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/02.Array-Sort/10.Array-Radix-Sort.md) -- 第 07 天课程题目: +- 第 08 天课程题目: - [1122. 数组的相对排序](https://leetcode.cn/problems/relative-sort-array/) - [0908. 最小差值 I](https://leetcode.cn/problems/smallest-range-i/) - [0164. 最大间距](https://leetcode.cn/problems/maximum-gap/) @@ -76,19 +81,19 @@ --- -### Task 04 数组二分查找(3 天) +### Task 04 数组二分查找( 第 09 ~ 11 天) -- 第 08 ~ 10 天学习内容: +- 第 09 ~ 11 天学习内容: - [二分查找知识](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/03.Array-Binary-Search/01.Array-Binary-Search.md) -- 第 08 天课程题目: +- 第 09 天课程题目: - [0704. 二分查找](https://leetcode.cn/problems/binary-search/) - [0035. 搜索插入位置](https://leetcode.cn/problems/search-insert-position/) - [0374. 猜数字大小](https://leetcode.cn/problems/guess-number-higher-or-lower/) -- 第 09 天课程题目: +- 第 10 天课程题目: - [0069. Sqrt(x)](https://leetcode.cn/problems/sqrtx/) - [0167. 两数之和 II - 输入有序数组](https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/) - [1011. 在 D 天内送达包裹的能力](https://leetcode.cn/problems/capacity-to-ship-packages-within-d-days/) -- 第 10 天课程题目: +- 第 11 天课程题目: - [0278. 第一个错误的版本](https://leetcode.cn/problems/first-bad-version/) - [0033. 搜索旋转排序数组](https://leetcode.cn/problems/search-in-rotated-sorted-array/) - [0153. 寻找旋转排序数组中的最小值](https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/) @@ -96,22 +101,22 @@ --- -### Task 05 数组双指针、滑动窗口(3 天) +### Task 05 数组双指针、滑动窗口(第 12 ~ 14 天) -- 第 11 ~ 12 天学习内容: +- 第 12 ~ 13 天学习内容: - [双指针基础知识](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/04.Array-Two-Pointers/01.Array-Two-Pointers.md) -- 第 11 天课程题目: +- 第 12 天课程题目: - [0344. 反转字符串](https://leetcode.cn/problems/reverse-string/) - [0015. 三数之和](https://leetcode.cn/problems/3sum/) - [0080. 删除有序数组中的重复项 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/) -- 第 12 天课程题目: +- 第 13 天课程题目: - [0283. 移动零](https://leetcode.cn/problems/move-zeroes/) - [0075. 颜色分类](https://leetcode.cn/problems/sort-colors/) - [0088. 合并两个有序数组](https://leetcode.cn/problems/merge-sorted-array/) - [更多双指针题目](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/04.Array-Two-Pointers/10.Array-Two-Pointers-List.md) -- 第 13 天学习内容: +- 第 14 天学习内容: - [滑动窗口基础知识](https://github.com/itcharge/LeetCode-Py/blob/main/Contents/01.Array/05.Array-Sliding-Window/01.Array-Sliding-Window.md) -- 第 13 天课程题目: +- 第 14 天课程题目: - [0674. 最长连续递增序列](https://leetcode.cn/problems/longest-continuous-increasing-subsequence/) - [1004. 最大连续1的个数 III](https://leetcode.cn/problems/max-consecutive-ones-iii/) - [0220. 存在重复元素 III](https://leetcode.cn/problems/contains-duplicate-iii/) diff --git a/Assets/Course/Course-Web-01.md b/Assets/Course/Course-Web-01.md index 9dfb4f99..c8d119ef 100644 --- a/Assets/Course/Course-Web-01.md +++ b/Assets/Course/Course-Web-01.md @@ -1,8 +1,8 @@ -# Leetcode 刷题课程第一期 +# Leetcode 刷题课程第 1 期:算法入门与数组篇 ## 课程信息 -- 学习周期:13 天,每天平均花费时间 1 小时 - 3 小时不等,根据个人学习接受能力强弱有所浮动。 +- 学习周期:14 天,每天平均花费时间 1 小时 - 3 小时不等,根据个人学习接受能力强弱有所浮动。 - 学习形式:理论学习 + 题目刷题 - 人群定位:有 Python 语言编程基础,想要学习算法、数据结构基础知识,想在 LeetCode 刷算法题的学员。 - 难度系数:⭐⭐⭐ @@ -17,9 +17,9 @@ --- -### Task 01:数据结构与算法简介、LeetCode 入门及攻略(1 天) +### Task 01:数据结构与算法简介、LeetCode 入门及攻略(第 01 ~ 02 天) -- 第 01 天学习内容: +- 第 01 ~ 02 天学习内容: - [数据结构与算法](https://algo.itcharge.cn/00.Introduction/01.Data-Structures-Algorithms/) - [算法复杂度](https://algo.itcharge.cn/00.Introduction/02.Algorithm-Complexity/) - [LeetCode 入门与指南](https://algo.itcharge.cn/00.Introduction/03.LeetCode-Guide/) @@ -27,18 +27,22 @@ - [0001. 两数之和](https://leetcode.cn/problems/two-sum/) - [1929. 数组串联](https://leetcode.cn/problems/concatenation-of-array/) - [0771. 宝石与石头](https://leetcode.cn/problems/jewels-and-stones/) +- 第 02 天课程题目列表: + - [1480. 一维数组的动态和](https://leetcode.cn/problems/running-sum-of-1d-array/) + - [0709. 转换成小写字母](https://leetcode.cn/problems/to-lower-case/) + - [1672. 最富有客户的资产总量](https://leetcode.cn/problems/richest-customer-wealth/) --- -### Task 02:数组基础(2 天) +### Task 02:数组基础(第 03 ~ 04 天) -- 第 02 ~ 03 天学习内容: +- 第 03 ~ 04 天学习内容: - [数组基础知识](https://algo.itcharge.cn/01.Array/01.Array-Basic/01.Array-Basic/) -- 第 02 天课程题目: +- 第 03 天课程题目: - [0066. 加一](https://leetcode.cn/problems/plus-one/) - [0724. 寻找数组的中心下标](https://leetcode.cn/problems/find-pivot-index/) - [0189. 旋转数组](https://leetcode.cn/problems/rotate-array/) -- 第 03 天课程题目: +- 第 04 天课程题目: - [0048. 旋转图像](https://leetcode.cn/problems/rotate-image/) - [0054. 螺旋矩阵](https://leetcode.cn/problems/spiral-matrix/) - [0498. 对角线遍历](https://leetcode.cn/problems/diagonal-traverse/) @@ -46,35 +50,35 @@ --- -### Task 03 数组排序(4 天) +### Task 03 数组排序(第 05 ~ 08 天) -- 第 04 天学习内容: +- 第 05 天学习内容: - [冒泡排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/01.Array-Bubble-Sort/) - [选择排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/02.Array-Selection-Sort/) - [插入排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/03.Array-Insertion-Sort/) -- 第 04 天课程题目: +- 第 05 天课程题目: - [剑指 Offer 45. 把数组排成最小的数](https://leetcode.cn/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) - [0283. 移动零](https://leetcode.cn/problems/move-zeroes/) - [0912. 排序数组](https://leetcode.cn/problems/sort-an-array/) -- 第 05 天学习内容: +- 第 06 天学习内容: - [希尔排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/04.Array-Shell-Sort/) - [归并排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/05.Array-Merge-Sort/) -- 第 05 天课程题目: +- 第 06 天课程题目: - [0506. 相对名次](https://leetcode.cn/problems/relative-ranks/) - [面试题 10.01. 合并排序的数组](https://leetcode.cn/problems/sorted-merge-lcci/) - [剑指 Offer 51. 数组中的逆序对](https://leetcode.cn/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) -- 第 06 天学习内容: +- 第 07 天学习内容: - [快速排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/06.Array-Quick-Sort/) - [堆排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/07.Array-Heap-Sort/) -- 第 06 天课程题目: +- 第 07 天课程题目: - [0075. 颜色分类](https://leetcode.cn/problems/sort-colors/) - [0215. 数组中的第K个最大元素](https://leetcode.cn/problems/kth-largest-element-in-an-array/) - [剑指 Offer 40. 最小的k个数](https://leetcode.cn/problems/zui-xiao-de-kge-shu-lcof/) -- 第 07 天学习内容: +- 第 08 天学习内容: - [计数排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/08.Array-Counting-Sort/) - [桶排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/09.Array-Bucket-Sort/) - [基数排序](https://algo.itcharge.cn/01.Array/02.Array-Sort/10.Array-Radix-Sort/) -- 第 07 天课程题目: +- 第 08 天课程题目: - [1122. 数组的相对排序](https://leetcode.cn/problems/relative-sort-array/) - [0908. 最小差值 I](https://leetcode.cn/problems/smallest-range-i/) - [0164. 最大间距](https://leetcode.cn/problems/maximum-gap/) @@ -82,19 +86,19 @@ --- -### Task 04 数组二分查找(3 天) +### Task 04 数组二分查找( 第 09 ~ 11 天) -- 第 08 ~ 10 天学习内容: +- 第 09 ~ 11 天学习内容: - [二分查找知识](https://algo.itcharge.cn/01.Array/03.Array-Binary-Search/01.Array-Binary-Search/) -- 第 08 天课程题目: +- 第 09 天课程题目: - [0704. 二分查找](https://leetcode.cn/problems/binary-search/) - [0035. 搜索插入位置](https://leetcode.cn/problems/search-insert-position/) - [0374. 猜数字大小](https://leetcode.cn/problems/guess-number-higher-or-lower/) -- 第 09 天课程题目: +- 第 10 天课程题目: - [0069. Sqrt(x)](https://leetcode.cn/problems/sqrtx/) - [0167. 两数之和 II - 输入有序数组](https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/) - [1011. 在 D 天内送达包裹的能力](https://leetcode.cn/problems/capacity-to-ship-packages-within-d-days/) -- 第 10 天课程题目: +- 第 11 天课程题目: - [0278. 第一个错误的版本](https://leetcode.cn/problems/first-bad-version/) - [0033. 搜索旋转排序数组](https://leetcode.cn/problems/search-in-rotated-sorted-array/) - [0153. 寻找旋转排序数组中的最小值](https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/) @@ -102,22 +106,22 @@ --- -### Task 05 数组双指针、滑动窗口(3 天) +### Task 05 数组双指针、滑动窗口(第 12 ~ 14 天) -- 第 11 ~ 12 天学习内容: +- 第 12 ~ 13 天学习内容: - [数组双指针知识](https://algo.itcharge.cn/01.Array/04.Array-Two-Pointers/01.Array-Two-Pointers/) -- 第 11 天课程题目: +- 第 12 天课程题目: - [0344. 反转字符串](https://leetcode.cn/problems/reverse-string/) - [0015. 三数之和](https://leetcode.cn/problems/3sum/) - [0080. 删除有序数组中的重复项 II](https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/) -- 第 12 天课程题目: +- 第 13 天课程题目: - [0283. 移动零](https://leetcode.cn/problems/move-zeroes/) - [0075. 颜色分类](https://leetcode.cn/problems/sort-colors/) - [0088. 合并两个有序数组](https://leetcode.cn/problems/merge-sorted-array/) - [更多数组双指针题目](https://algo.itcharge.cn/01.Array/04.Array-Two-Pointers/02.Array-Two-Pointers-List/) -- 第 13 天学习内容: +- 第 14 天学习内容: - [数组滑动窗口知识](https://algo.itcharge.cn/01.Array/05.Array-Sliding-Window/01.Array-Sliding-Window/) -- 第 13 天课程题目: +- 第 14 天课程题目: - [0674. 最长连续递增序列](https://leetcode.cn/problems/longest-continuous-increasing-subsequence/) - [1004. 最大连续1的个数 III](https://leetcode.cn/problems/max-consecutive-ones-iii/) - [0220. 存在重复元素 III](https://leetcode.cn/problems/contains-duplicate-iii/)

AltStyle によって変換されたページ (->オリジナル) /