From 8ea6473d0287d15c33a7b7c29405df1444ca06b6 Mon Sep 17 00:00:00 2001 From: ITCharge Date: 2024年1月15日 11:51:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Contents/00.Introduction/04.Solutions-List.md | 5 +- README.md | 2 +- ...57345円220円246円346円216円245円350円277円221円.md" | 77 ++++++++++++++++ ...14347円247円257円345円205円203円347円273円204円.md" | 78 +++++++++++++++++ ...00345円244円247円346円225円260円351円207円217円.md" | 87 +++++++++++++++++++ 5 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 "Solutions/1657. 347円241円256円345円256円232円344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円346円230円257円345円220円246円346円216円245円350円277円221円.md" create mode 100644 "Solutions/1726. 345円220円214円347円247円257円345円205円203円347円273円204円.md" create mode 100644 "Solutions/1921. 346円266円210円347円201円255円346円200円252円347円211円251円347円232円204円346円234円200円345円244円247円346円225円260円351円207円217円.md" diff --git a/Contents/00.Introduction/04.Solutions-List.md b/Contents/00.Introduction/04.Solutions-List.md index 6e4fa944..938051cc 100644 --- a/Contents/00.Introduction/04.Solutions-List.md +++ b/Contents/00.Introduction/04.Solutions-List.md @@ -1,4 +1,4 @@ -# LeetCode 题解(已完成 847 道) +# LeetCode 题解(已完成 850 道) | 题号 | 标题 | 题解 | 标签 | 难度 | | :------ | :------ | :------ | :------ | :------ | @@ -600,6 +600,7 @@ | 1617 | [统计子树中城市之间最大距离](https://leetcode.cn/problems/count-subtrees-with-max-distance-between-cities/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1617.%20%E7%BB%9F%E8%AE%A1%E5%AD%90%E6%A0%91%E4%B8%AD%E5%9F%8E%E5%B8%82%E4%B9%8B%E9%97%B4%E6%9C%80%E5%A4%A7%E8%B7%9D%E7%A6%BB.md) | 位运算、树、动态规划、状态压缩、枚举 | 困难 | | 1631 | [最小体力消耗路径](https://leetcode.cn/problems/path-with-minimum-effort/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1631.%20%E6%9C%80%E5%B0%8F%E4%BD%93%E5%8A%9B%E6%B6%88%E8%80%97%E8%B7%AF%E5%BE%84.md) | 深度优先搜索、广度优先搜索、并查集、数组、二分查找、矩阵、堆(优先队列) | 中等 | | 1646 | [获取生成数组中的最大值](https://leetcode.cn/problems/get-maximum-in-generated-array/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1646.%20%E8%8E%B7%E5%8F%96%E7%94%9F%E6%88%90%E6%95%B0%E7%BB%84%E4%B8%AD%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC.md) | 数组、动态规划、模拟 | 简单 | +| 1657 | [确定两个字符串是否接近](https://leetcode.cn/problems/determine-if-two-strings-are-close/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1657.%20%E7%A1%AE%E5%AE%9A%E4%B8%A4%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%AF%E5%90%A6%E6%8E%A5%E8%BF%91.md) | 哈希表、字符串、排序 | 中等 | | 1658 | [将 x 减到 0 的最小操作数](https://leetcode.cn/problems/minimum-operations-to-reduce-x-to-zero/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1658.%20%E5%B0%86%20x%20%E5%87%8F%E5%88%B0%200%20%E7%9A%84%E6%9C%80%E5%B0%8F%E6%93%8D%E4%BD%9C%E6%95%B0.md) | 数组、哈希表、二分查找、前缀和、滑动窗口 | 中等 | | 1672 | [最富有客户的资产总量](https://leetcode.cn/problems/richest-customer-wealth/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1672.%20%E6%9C%80%E5%AF%8C%E6%9C%89%E5%AE%A2%E6%88%B7%E7%9A%84%E8%B5%84%E4%BA%A7%E6%80%BB%E9%87%8F.md) | 数组、矩阵 | 简单 | | 1695 | [删除子数组的最大得分](https://leetcode.cn/problems/maximum-erasure-value/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1695.%20%E5%88%A0%E9%99%A4%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E6%9C%80%E5%A4%A7%E5%BE%97%E5%88%86.md) | 数组、哈希表、滑动窗口 | 中等 | @@ -607,6 +608,7 @@ | 1710 | [卡车上的最大单元数](https://leetcode.cn/problems/maximum-units-on-a-truck/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1710.%20%E5%8D%A1%E8%BD%A6%E4%B8%8A%E7%9A%84%E6%9C%80%E5%A4%A7%E5%8D%95%E5%85%83%E6%95%B0.md) | 贪心、数组、排序 | 简单 | | 1716 | [计算力扣银行的钱](https://leetcode.cn/problems/calculate-money-in-leetcode-bank/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1716.%20%E8%AE%A1%E7%AE%97%E5%8A%9B%E6%89%A3%E9%93%B6%E8%A1%8C%E7%9A%84%E9%92%B1.md) | 数学 | 简单 | | 1720 | [解码异或后的数组](https://leetcode.cn/problems/decode-xored-array/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1720.%20%E8%A7%A3%E7%A0%81%E5%BC%82%E6%88%96%E5%90%8E%E7%9A%84%E6%95%B0%E7%BB%84.md) | 位运算、数组 | 简单 | +| 1726 | [同积元组](https://leetcode.cn/problems/tuple-with-same-product/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1726.%20%E5%90%8C%E7%A7%AF%E5%85%83%E7%BB%84.md) | 数组、哈希表 | 中等 | | 1736 | [替换隐藏数字得到的最晚时间](https://leetcode.cn/problems/latest-time-by-replacing-hidden-digits/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1736.%20%E6%9B%BF%E6%8D%A2%E9%9A%90%E8%97%8F%E6%95%B0%E5%AD%97%E5%BE%97%E5%88%B0%E7%9A%84%E6%9C%80%E6%99%9A%E6%97%B6%E9%97%B4.md) | 贪心、字符串 | 简单 | | 1742 | [盒子中小球的最大数量](https://leetcode.cn/problems/maximum-number-of-balls-in-a-box/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1742.%20%E7%9B%92%E5%AD%90%E4%B8%AD%E5%B0%8F%E7%90%83%E7%9A%84%E6%9C%80%E5%A4%A7%E6%95%B0%E9%87%8F.md) | 哈希表、数学、计数 | 简单 | | 1749 | [任意子数组和的绝对值的最大值](https://leetcode.cn/problems/maximum-absolute-sum-of-any-subarray/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1749.%20%E4%BB%BB%E6%84%8F%E5%AD%90%E6%95%B0%E7%BB%84%E5%92%8C%E7%9A%84%E7%BB%9D%E5%AF%B9%E5%80%BC%E7%9A%84%E6%9C%80%E5%A4%A7%E5%80%BC.md) | 数组、动态规划 | 中等 | @@ -625,6 +627,7 @@ | 1893 | [检查是否区域内所有整数都被覆盖](https://leetcode.cn/problems/check-if-all-the-integers-in-a-range-are-covered/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1893.%20%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8C%BA%E5%9F%9F%E5%86%85%E6%89%80%E6%9C%89%E6%95%B4%E6%95%B0%E9%83%BD%E8%A2%AB%E8%A6%86%E7%9B%96.md) | 数组、哈希表、前缀和 | 简单 | | 1897 | [重新分配字符使所有字符串都相等](https://leetcode.cn/problems/redistribute-characters-to-make-all-strings-equal/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1897.%20%E9%87%8D%E6%96%B0%E5%88%86%E9%85%8D%E5%AD%97%E7%AC%A6%E4%BD%BF%E6%89%80%E6%9C%89%E5%AD%97%E7%AC%A6%E4%B8%B2%E9%83%BD%E7%9B%B8%E7%AD%89.md) | 哈希表、字符串、计数 | 简单 | | 1903 | [字符串中的最大奇数](https://leetcode.cn/problems/largest-odd-number-in-string/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1903.%20%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E7%9A%84%E6%9C%80%E5%A4%A7%E5%A5%87%E6%95%B0.md) | 贪心、数学、字符串 | 简单 | +| 1921 | [消灭怪物的最大数量](https://leetcode.cn/problems/eliminate-maximum-number-of-monsters/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1921.%20%E6%B6%88%E7%81%AD%E6%80%AA%E7%89%A9%E7%9A%84%E6%9C%80%E5%A4%A7%E6%95%B0%E9%87%8F.md) | 贪心、数组、排序 | 中等 | | 1925 | [统计平方和三元组的数目](https://leetcode.cn/problems/count-square-sum-triples/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1925.%20%E7%BB%9F%E8%AE%A1%E5%B9%B3%E6%96%B9%E5%92%8C%E4%B8%89%E5%85%83%E7%BB%84%E7%9A%84%E6%95%B0%E7%9B%AE.md) | 数学、枚举 | 简单 | | 1929 | [数组串联](https://leetcode.cn/problems/concatenation-of-array/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1929.%20%E6%95%B0%E7%BB%84%E4%B8%B2%E8%81%94.md) | 数组 | 简单 | | 1930 | [长度为 3 的不同回文子序列](https://leetcode.cn/problems/unique-length-3-palindromic-subsequences/) | [Python](https://github.com/itcharge/LeetCode-Py/blob/main/Solutions/1930.%20%E9%95%BF%E5%BA%A6%E4%B8%BA%203%20%E7%9A%84%E4%B8%8D%E5%90%8C%E5%9B%9E%E6%96%87%E5%AD%90%E5%BA%8F%E5%88%97.md) | 哈希表、字符串、前缀和 | 中等 | diff --git a/README.md b/README.md index 25322b95..3ee255d0 100644 --- a/README.md +++ b/README.md @@ -255,4 +255,4 @@ - [动态规划优化题目](./Contents/10.Dynamic-Programming/11.DP-Optimization/04.DP-Optimization-List.md) ## 11. 附加内容 -## [12. LeetCode 题解(已完成 847 道)](./Contents/00.Introduction/04.Solutions-List.md) \ No newline at end of file +## [12. LeetCode 题解(已完成 850 道)](./Contents/00.Introduction/04.Solutions-List.md) \ No newline at end of file diff --git "a/Solutions/1657. 347円241円256円345円256円232円344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円346円230円257円345円220円246円346円216円245円350円277円221円.md" "b/Solutions/1657. 347円241円256円345円256円232円344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円346円230円257円345円220円246円346円216円245円350円277円221円.md" new file mode 100644 index 00000000..fa995021 --- /dev/null +++ "b/Solutions/1657. 347円241円256円345円256円232円344円270円244円344円270円252円345円255円227円347円254円246円344円270円262円346円230円257円345円220円246円346円216円245円350円277円221円.md" @@ -0,0 +1,77 @@ +# [1657. 确定两个字符串是否接近](https://leetcode.cn/problems/determine-if-two-strings-are-close/) + +- 标签:哈希表、字符串、排序 +- 难度:中等 + +## 题目链接 + +- [1657. 确定两个字符串是否接近 - 力扣](https://leetcode.cn/problems/determine-if-two-strings-are-close/) + +## 题目大意 + +**描述**:如果可以使用以下操作从一个字符串得到另一个字符串,则认为两个字符串 接近 : + +- 操作 1:交换任意两个现有字符。 + - 例如,`abcde` -> `aecdb`。 +- 操作 2:将一个 现有 字符的每次出现转换为另一个现有字符,并对另一个字符执行相同的操作。 + - 例如,`aacabb` -> `bbcbaa`(所有 `a` 转化为 `b`,而所有的 `b` 转换为 `a` )。 + +给定两个字符串,$word1$ 和 $word2$。 + +**要求**:如果 $word1$ 和 $word2$ 接近 ,就返回 $True$;否则,返回 $False$。 + +**说明**: + +- 1ドル \le word1.length, word2.length \le 10^5$。 +- $word1$ 和 $word2$ 仅包含小写英文字母。 + +**示例**: + +- 示例 1: + +```python +输入:word1 = "abc", word2 = "bca" +输出:True +解释:2 次操作从 word1 获得 word2 。 +执行操作 1:"abc" -> "acb" +执行操作 1:"acb" -> "bca" +``` + +- 示例 2: + +```python +输入:word1 = "a", word2 = "aa" +输出:False +解释:不管执行多少次操作,都无法从 word1 得到 word2 ,反之亦然。 +``` + +## 解题思路 + +### 思路 1:模拟 + +无论是操作 1,还是操作 2,只是对字符位置进行交换,而不会产生或者删除字符。 + +则我们只需要检查两个字符串的字符种类以及每种字符的个数是否相同即可。 + +具体步骤如下: + +1. 分别使用哈希表 $cnts1$、$cnts2$ 统计每个字符串中的字符种类,每种字符的个数。 +2. 判断两者的字符种类是否相等,并且判断每种字符的个数是否相同。 +3. 如果字符种类相同,且每种字符的个数完全相同,则返回 $True,ドル否则,返回 $False$。 + +### 思路 1:代码 + +```Python +class Solution: + def closeStrings(self, word1: str, word2: str) -> bool: + cnts1 = Counter(word1) + cnts2 = Counter(word2) + + return cnts1.keys() == cnts2.keys() and sorted(cnts1.values()) == sorted(cnts2.values()) +``` + +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(max(n1, n2) + |\sum| \times \log | \sum |),ドル其中 $n1$、$n2$ 分别为字符串 $word1$、$word2$ 的长度,$\sum$ 为字符集,本题中 $| \sum | = 26$。 +- **空间复杂度**:$O(| \sum |)$。 + diff --git "a/Solutions/1726. 345円220円214円347円247円257円345円205円203円347円273円204円.md" "b/Solutions/1726. 345円220円214円347円247円257円345円205円203円347円273円204円.md" new file mode 100644 index 00000000..86483c7b --- /dev/null +++ "b/Solutions/1726. 345円220円214円347円247円257円345円205円203円347円273円204円.md" @@ -0,0 +1,78 @@ +# [1726. 同积元组](https://leetcode.cn/problems/tuple-with-same-product/) + +- 标签:数组、哈希表 +- 难度:中等 + +## 题目链接 + +- [1726. 同积元组 - 力扣](https://leetcode.cn/problems/tuple-with-same-product/) + +## 题目大意 + +**描述**:给定一个由不同正整数组成的数组 $nums$。 + +**要求**:返回满足 $a \times b = c \times d$ 的元组 $(a, b, c, d)$ 的数量。其中 $a$、$b$、$c$ 和 $d$ 都是 $nums$ 中的元素,且 $a \ne b \ne c \ne d$。 + +**说明**: + +- 1ドル \le nums.length \le 1000$。 +- 1ドル \le nums[i] \le 10^4$。 +- $nums$ 中的所有元素互不相同。 + +**示例**: + +- 示例 1: + +```python +输入:nums = [2,3,4,6] +输出:8 +解释:存在 8 个满足题意的元组: +(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3) +(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2) +``` + +- 示例 2: + +```python +输入:nums = [1,2,4,5,10] +输出:16 +解释:存在 16 个满足题意的元组: +(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2) +(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1) +(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4) +(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2) +``` + +## 解题思路 + +### 思路 1:哈希表 + 数学 + +1. 二重循环遍历数组 $nums,ドル使用哈希表 $cnts$ 记录下所有不同 $nums[i] \times nums[j]$ 的结果。 +2. 因为满足 $a \times b = c \times d$ 的元组 $(a, b, c, d)$ 可以按照不同顺序进行组和,所以对于 $x$ 个 $nums[i] \times nums[j],ドル就有 $C_x^2$ 种组和方法。 +3. 遍历哈希表 $cnts$ 中所有值 $value,ドル将不同组和的方法数累积到答案 $ans$ 中。 +4. 遍历完返回答案 $ans$。 + +### 思路 1:代码 + +```Python +class Solution: + def tupleSameProduct(self, nums: List[int]) -> int: + cnts = Counter() + size = len(nums) + for i in range(size): + for j in range(i + 1, size): + product = nums[i] * nums[j] + cnts[product] += 1 + + ans = 0 + for key, value in cnts.items(): + ans += value * (value - 1) * 4 + + return ans +``` + +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n^2),ドル其中 $n$ 表示数组 $nums$ 的长度。 +- **空间复杂度**:$O(n^2)$。 + diff --git "a/Solutions/1921. 346円266円210円347円201円255円346円200円252円347円211円251円347円232円204円346円234円200円345円244円247円346円225円260円351円207円217円.md" "b/Solutions/1921. 346円266円210円347円201円255円346円200円252円347円211円251円347円232円204円346円234円200円345円244円247円346円225円260円351円207円217円.md" new file mode 100644 index 00000000..5ddee890 --- /dev/null +++ "b/Solutions/1921. 346円266円210円347円201円255円346円200円252円347円211円251円347円232円204円346円234円200円345円244円247円346円225円260円351円207円217円.md" @@ -0,0 +1,87 @@ +# [1921. 消灭怪物的最大数量](https://leetcode.cn/problems/eliminate-maximum-number-of-monsters/) + +- 标签:贪心、数组、排序 +- 难度:中等 + +## 题目链接 + +- [1921. 消灭怪物的最大数量 - 力扣](https://leetcode.cn/problems/eliminate-maximum-number-of-monsters/) + +## 题目大意 + +**描述**:你正在玩一款电子游戏,在游戏中你需要保护城市免受怪物侵袭。给定一个下标从 0ドル$ 开始且大小为 $n$ 的整数数组 $dist,ドル其中 $dist[i]$ 是第 $i$ 个怪物与城市的初始距离(单位:米)。 + +怪物以恒定的速度走向城市。每个怪物的速度都以一个长度为 $n$ 的整数数组 $speed$ 表示,其中 $speed[i]$ 是第 $i$ 个怪物的速度(单位:千米/分)。 + +你有一种武器,一旦充满电,就可以消灭 一个 怪物。但是,武器需要 一分钟 才能充电。武器在游戏开始时是充满电的状态,怪物从 第 0ドル$ 分钟时开始移动。 + +一旦任一怪物到达城市,你就输掉了这场游戏。如果某个怪物 恰好 在某一分钟开始时到达城市(距离表示为 0ドル$),这也会被视为输掉 游戏,在你可以使用武器之前,游戏就会结束。 + +**要求**:返回在你输掉游戏前可以消灭的怪物的最大数量。如果你可以在所有怪物到达城市前将它们全部消灭,返回 $n$。 + +**说明**: + +- + +**示例**: + +- 示例 1: + +```python +输入:dist = [1,3,4], speed = [1,1,1] +输出:3 +解释: +第 0 分钟开始时,怪物的距离是 [1,3,4],你消灭了第一个怪物。 +第 1 分钟开始时,怪物的距离是 [X,2,3],你消灭了第二个怪物。 +第 3 分钟开始时,怪物的距离是 [X,X,2],你消灭了第三个怪物。 +所有 3 个怪物都可以被消灭。 +``` + +- 示例 2: + +```python +输入:dist = [1,1,2,3], speed = [1,1,1,1] +输出:1 +解释: +第 0 分钟开始时,怪物的距离是 [1,1,2,3],你消灭了第一个怪物。 +第 1 分钟开始时,怪物的距离是 [X,0,1,2],所以你输掉了游戏。 +你只能消灭 1 个怪物。 +``` + +## 解题思路 + +### 思路 1:排序 + 贪心算法 + +对于第 $i$ 个怪物,最晚可被消灭的时间为 $times[i] = \lfloor \frac{dist[i] - 1}{speed[i]} \rfloor$。我们可以根据以上公式,将所有怪物最晚可被消灭时间存入数组 $times$ 中,然后对 $times$ 进行升序排序。 + +然后遍历数组 $times,ドル对于第 $i$ 个怪物: + +1. 如果 $times[i] < i,ドル则说明第 $i$ 个怪物无法被消灭,直接返回 $i$ 即可。 +2. 如果 $times[i] \ge i,ドル则说明第 $i$ 个怪物可以被消灭,继续向下遍历。 + +如果遍历完数组 $times,ドル则说明所有怪物都可以被消灭,则返回 $n$。 + +### 思路 1:代码 + +```Python +class Solution: + def eliminateMaximum(self, dist: List[int], speed: List[int]) -> int: + times = [] + for d, s in zip(dist, speed): + time = (d - 1) // s + times.append(time) + times.sort() + + size = len(times) + for i in range(size): + if times[i] < i: + return i + + return size +``` + +### 思路 1:复杂度分析 + +- **时间复杂度**:$O(n \times \log n),ドル其中 $n$ 为数组 $dist$ 的长度。 +- **空间复杂度**:$O(n)$。 + From 6596885f1e59070540f10e4748bd4a8f0a50b37c Mon Sep 17 00:00:00 2001 From: ITCharge Date: 2024年1月15日 20:11:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A2=98=E8=A7=A3?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00351円225円277円345円255円220円344円270円262円.md" | 2 +- ...345244円215円345円205円203円347円264円240円 II.md" | 14 ++++++------ ...15345円244円215円345円205円203円347円264円240円.md" | 8 +++---- ...25350円257円215円346円213円206円345円210円206円.md" | 22 +++++++++---------- ...15346円216円222円351円223円276円350円241円250円.md" | 4 ++-- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git "a/Solutions/0003. 346円227円240円351円207円215円345円244円215円345円255円227円347円254円246円347円232円204円346円234円200円351円225円277円345円255円220円344円270円262円.md" "b/Solutions/0003. 346円227円240円351円207円215円345円244円215円345円255円227円347円254円246円347円232円204円346円234円200円351円225円277円345円255円220円344円270円262円.md" index eba49ead..888ebc90 100644 --- "a/Solutions/0003. 346円227円240円351円207円215円345円244円215円345円255円227円347円254円246円347円232円204円346円234円200円351円225円277円345円255円220円344円270円262円.md" +++ "b/Solutions/0003. 346円227円240円351円207円215円345円244円215円345円255円227円347円254円246円347円232円204円346円234円200円351円225円277円345円255円220円344円270円262円.md" @@ -16,7 +16,7 @@ **说明**: - 0ドル \le s.length \le 5 * 10^4$。 -- `s` 由英文字母、数字、符号和空格组成。 +- $s$ 由英文字母、数字、符号和空格组成。 **示例**: diff --git "a/Solutions/0082. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円 II.md" "b/Solutions/0082. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円 II.md" index 912d2e22..13d9b780 100644 --- "a/Solutions/0082. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円 II.md" +++ "b/Solutions/0082. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円 II.md" @@ -9,7 +9,7 @@ ## 题目大意 -**描述**:给定一个已排序的链表的头 `head`。 +**描述**:给定一个已排序的链表的头 $head$。 **要求**:删除原始链表中所有重复数字的节点,只留下不同的数字。返回已排序的链表。 @@ -34,12 +34,12 @@ 这道题的题意是需要保留所有不同数字,而重复出现的所有数字都要删除。因为给定的链表是升序排列的,所以我们要删除的重复元素在链表中的位置是连续的。所以我们可以对链表进行一次遍历,然后将连续的重复元素从链表中删除即可。具体步骤如下: -- 先使用哑节点 `dummy_head` 构造一个指向 `head` 的指针,使得可以防止从 `head` 开始就是重复元素。 -- 然后使用指针 `cur` 表示链表中当前元素,从 `head` 开始遍历。 -- 当指针 `cur` 的下一个元素和下下一个元素存在时: - - 如果下一个元素值和下下一个元素值相同,则我们使用指针 `temp` 保存下一个元素,并使用 `temp` 向后遍历,跳过所有重复元素,然后令 `cur` 的下一个元素指向 `temp` 的下一个元素,继续向后遍历。 - - 如果下一个元素值和下下一个元素值不同,则令 `cur` 向右移动一位,继续向后遍历。 -- 当指针 `cur` 的下一个元素或者下下一个元素不存在时,说明已经遍历完,则返回哑节点 `dummy_head` 的下一个节点作为头节点。 +- 先使用哑节点 $dummy\underline{}head$ 构造一个指向 $head$ 的指针,使得可以防止从 $head$ 开始就是重复元素。 +- 然后使用指针 $cur$ 表示链表中当前元素,从 $head$ 开始遍历。 +- 当指针 $cur$ 的下一个元素和下下一个元素存在时: + - 如果下一个元素值和下下一个元素值相同,则我们使用指针 $temp$ 保存下一个元素,并使用 $temp$ 向后遍历,跳过所有重复元素,然后令 $cur$ 的下一个元素指向 $temp$ 的下一个元素,继续向后遍历。 + - 如果下一个元素值和下下一个元素值不同,则令 $cur$ 向右移动一位,继续向后遍历。 +- 当指针 $cur$ 的下一个元素或者下下一个元素不存在时,说明已经遍历完,则返回哑节点 $dummy\underline{}head$ 的下一个节点作为头节点。 ### 思路 1:代码 diff --git "a/Solutions/0083. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円.md" "b/Solutions/0083. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円.md" index 0d2f52e6..f4f0f90a 100644 --- "a/Solutions/0083. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円.md" +++ "b/Solutions/0083. 345円210円240円351円231円244円346円216円222円345円272円217円351円223円276円350円241円250円344円270円255円347円232円204円351円207円215円345円244円215円345円205円203円347円264円240円.md" @@ -9,7 +9,7 @@ ## 题目大意 -**描述**:给定一个已排序的链表的头 `head`。 +**描述**:给定一个已排序的链表的头 $head$。 **要求**:删除所有重复的元素,使每个元素只出现一次。返回已排序的链表。 @@ -32,11 +32,11 @@ ### 思路 1:遍历 -- 使用指针 `curr` 遍历链表,先将 `head` 保存到 `curr` 指针。 +- 使用指针 $curr$ 遍历链表,先将 $head$ 保存到 $curr$ 指针。 - 判断当前元素的值和当前元素下一个节点元素值是否相等。 - 如果相等,则让当前指针指向当前指针下两个节点。 -- 否则,让 `curr` 继续向后遍历。 -- 遍历完之后返回头节点 `head`。 +- 否则,让 $curr$ 继续向后遍历。 +- 遍历完之后返回头节点 $head$。 ### 思路 1:遍历代码 diff --git "a/Solutions/0139. 345円215円225円350円257円215円346円213円206円345円210円206円.md" "b/Solutions/0139. 345円215円225円350円257円215円346円213円206円345円210円206円.md" index 5a3604c0..309de356 100644 --- "a/Solutions/0139. 345円215円225円350円257円215円346円213円206円345円210円206円.md" +++ "b/Solutions/0139. 345円215円225円350円257円215円346円213円206円345円210円206円.md" @@ -9,9 +9,9 @@ ## 题目大意 -**描述**:给定一个非空字符串 `s` 和一个包含非空单词的列表 `wordDict` 作为字典。 +**描述**:给定一个非空字符串 $s$ 和一个包含非空单词的列表 $wordDict$ 作为字典。 -**要求**:判断是否可以利用字典中出现的单词拼接出 `s` 。 +**要求**:判断是否可以利用字典中出现的单词拼接出 $s$ 。 **说明**: @@ -19,8 +19,8 @@ - 1ドル \le s.length \le 300$。 - 1ドル \le wordDict.length \le 1000$。 - 1ドル \le wordDict[i].length \le 20$。 -- `s` 和 `wordDict[i]` 仅有小写英文字母组成。 -- `wordDict` 中的所有字符串互不相同。 +- $s$ 和 $wordDict[i]$ 仅有小写英文字母组成。 +- $wordDict$ 中的所有字符串互不相同。 **示例**: @@ -51,25 +51,25 @@ ###### 2. 定义状态 -`s` 能否拆分为单词表的单词,可以分解为: +$s$ 能否拆分为单词表的单词,可以分解为: - 前 $i$ 个字符构成的字符串,能否分解为单词。 - 剩余字符串,能否分解为单词。 -定义状态 `dp[i]` 表示:长度为 $i$ 的字符串 `s[0: i]` 能否拆分成单词,如果为 `True` 则表示可以拆分,如果为 `False` 则表示不能拆分。 +定义状态 $dp[i]$ 表示:长度为 $i$ 的字符串 $s[0: i]$ 能否拆分成单词,如果为 $True$ 则表示可以拆分,如果为 $False$ 则表示不能拆分。 ###### 3. 状态转移方程 -- 如果 `s[0: j]` 可以拆分为单词(即 `dp[j] == True`),并且字符串 `s[j: i]` 出现在字典中,则 `dp[i] = True`。 -- 如果 `s[0: j]` 不可以拆分为单词(即 `dp[j] == False`),或者字符串 `s[j: i]` 没有出现在字典中,则 `dp[i] = False`。 +- 如果 $s[0: j]$ 可以拆分为单词(即 $dp[j] == True$),并且字符串 $s[j: i]$ 出现在字典中,则 `dp[i] = True`。 +- 如果 $s[0: j]$ 不可以拆分为单词(即 $dp[j] == False$),或者字符串 $s[j: i]$ 没有出现在字典中,则 `dp[i] = False`。 ###### 4. 初始条件 -- 长度为 0ドル$ 的字符串 `s[0: i]` 可以拆分为单词,即 `dp[0] = True`。 +- 长度为 0ドル$ 的字符串 $s[0: i]$ 可以拆分为单词,即 $dp[0] = True$。 ###### 5. 最终结果 -根据我们之前定义的状态,`dp[i]` 表示:长度为 $i$ 的字符串 `s[0: i]` 能否拆分成单词。则最终结果为 `dp[size]`,`size` 为字符串长度。 +根据我们之前定义的状态,$dp[i]$ 表示:长度为 $i$ 的字符串 $s[0: i]$ 能否拆分成单词。则最终结果为 $dp[size],ドル$size$ 为字符串长度。 ### 思路 1:代码 @@ -88,6 +88,6 @@ class Solution: ### 思路 1:复杂度分析 -- **时间复杂度**:$O(n^2),ドル其中 $n$ 为字符串 `s` 的长度。 +- **时间复杂度**:$O(n^2),ドル其中 $n$ 为字符串 $s$ 的长度。 - **空间复杂度**:$O(n)$。 diff --git "a/Solutions/0143. 351円207円215円346円216円222円351円223円276円350円241円250円.md" "b/Solutions/0143. 351円207円215円346円216円222円351円223円276円350円241円250円.md" index 92bb734f..3240f331 100644 --- "a/Solutions/0143. 351円207円215円346円216円222円351円223円276円350円241円250円.md" +++ "b/Solutions/0143. 351円207円215円346円216円222円351円223円276円350円241円250円.md" @@ -9,9 +9,9 @@ ## 题目大意 -**描述**:给定一个单链表 `L` 的头节点 `head`,单链表 `L` 表示为:$L_0$ -> $L_1$ -> $L_2$ -> ... -> $L_{n-1}$ -> $L_n$。 +**描述**:给定一个单链表 $L$ 的头节点 $head,ドル单链表 $L$ 表示为:$L_0 \rightarrow L_1 \rightarrow L_2 \rightarrow ... \rightarrow L_{n-1} \rightarrow L_n$。 -**要求**:将单链表 `L` 重新排列为:$L_0$ -> $L_n$ -> $L_1$ -> $L_{n-1}$ -> $L_2$ -> $L_{n-2}$ -> $L_3$ -> $L_{n-3}$ -> ...。 +**要求**:将单链表 $L$ 重新排列为:$L_0 \rightarrow L_n \rightarrow L_1 \rightarrow L_{n-1} \rightarrow L_2 \rightarrow L_{n-2} \rightarrow L_3 \rightarrow L_{n-3} \rightarrow ...$。 **说明**:

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