Skip to content

Commit db80e85

Browse files
committed
补充第 400 ~ 499 题的题目解析(增加 15 道题)
1 parent 37ab2c3 commit db80e85

20 files changed

+1647
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
本书不仅仅只是一本算法题解书,更是一本算法与数据结构基础知识的讲解书。
2626

27-
- 超详细的 **「算法与数据结构」** 基础讲解教程,**「LeetCode 800+ 道」** 经典题目详细解析。
27+
- 超详细的 **「算法与数据结构」** 基础讲解教程,**「LeetCode 1000+ 道」** 经典题目详细解析。
2828
- 本项目易于理解,没有大跨度的思维跳跃,项目中使用大量图示、例子来帮助理解。
2929
- 本项目先从基础的数据结构和算法开始讲解,再针对不同分类的数据结构和算法,进行具体题目的讲解分析。让读者可以通过「算法基础理论学习」和「编程实战学习」相结合的方式,彻底的掌握算法知识。
3030
- 本项目从各大知名互联网公司面试算法题中整理汇总了 **「LeetCode 200 道高频面试题」**,帮助面试者更有针对性的准备面试。
@@ -66,7 +66,7 @@
6666

6767
我是一名 iOS / macOS 的开发程序员,研究生毕业于北航软件学院。曾在大学期间学习过算法知识,并参加过 3 年的 ACM 比赛, 但水平有限,未能取得理想成绩。但是这 3 年的 ACM 经历,给我最大的收获是锻炼了自己的逻辑思维和解决实际问题的能力,这种能力为我今后的工作、学习打下了坚实的基础。
6868

69-
我从 2021 年 03 月 30 日开始每日在 LeetCode 刷题,到目前为止日已经刷了 1000+ 道题目,并且完成了 800+ 道题解。努力向着 1000+、1500+、2000+ 道题解前进。
69+
我从 2021 年 03 月 30 日开始每日在 LeetCode 刷题,到目前为止日已经刷了 1800+ 道题目,并且完成了 1000+ 道题解。努力向着 1500+、2000+ 道题解前进。
7070

7171
### 2.2 互助与勘误
7272

docs/00_preface/00_05_solutions_list.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# LeetCode 题解(已完成 985 道)
1+
# LeetCode 题解(已完成 1000 道)
22

33
### 第 1 ~ 99 题
44

@@ -431,32 +431,47 @@
431431
| [0429. N 叉树的层序遍历](https://leetcode.cn/problems/n-ary-tree-level-order-traversal/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/n-ary-tree-level-order-traversal.md) | 树、广度优先搜索 | 中等 |
432432
| [0430. 扁平化多级双向链表](https://leetcode.cn/problems/flatten-a-multilevel-doubly-linked-list/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/flatten-a-multilevel-doubly-linked-list.md) | 深度优先搜索、链表、双向链表 | 中等 |
433433
| [0432. 全 O(1) 的数据结构](https://leetcode.cn/problems/all-oone-data-structure/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/all-oone-data-structure.md) | 设计、哈希表、链表、双向链表 | 困难 |
434+
| [0433. 最小基因变化](https://leetcode.cn/problems/minimum-genetic-mutation/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/minimum-genetic-mutation.md) | 广度优先搜索、哈希表、字符串 | 中等 |
434435
| [0435. 无重叠区间](https://leetcode.cn/problems/non-overlapping-intervals/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/non-overlapping-intervals.md) | 贪心、数组、动态规划、排序 | 中等 |
436+
| [0436. 寻找右区间](https://leetcode.cn/problems/find-right-interval/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/find-right-interval.md) | 数组、二分查找、排序 | 中等 |
435437
| [0437. 路径总和 III](https://leetcode.cn/problems/path-sum-iii/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/path-sum-iii.md) | 树、深度优先搜索、二叉树 | 中等 |
436438
| [0438. 找到字符串中所有字母异位词](https://leetcode.cn/problems/find-all-anagrams-in-a-string/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/find-all-anagrams-in-a-string.md) | 哈希表、字符串、滑动窗口 | 中等 |
439+
| [0440. 字典序的第K小数字](https://leetcode.cn/problems/k-th-smallest-in-lexicographical-order/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/k-th-smallest-in-lexicographical-order.md) | 字典树 | 困难 |
437440
| [0441. 排列硬币](https://leetcode.cn/problems/arranging-coins/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/arranging-coins.md) | 数学、二分查找 | 简单 |
441+
| [0442. 数组中重复的数据](https://leetcode.cn/problems/find-all-duplicates-in-an-array/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/find-all-duplicates-in-an-array.md) | 数组、哈希表 | 中等 |
438442
| [0443. 压缩字符串](https://leetcode.cn/problems/string-compression/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/string-compression.md) | 双指针、字符串 | 中等 |
439443
| [0445. 两数相加 II](https://leetcode.cn/problems/add-two-numbers-ii/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/add-two-numbers-ii.md) | 栈、链表、数学 | 中等 |
440444
| [0446. 等差数列划分 II - 子序列](https://leetcode.cn/problems/arithmetic-slices-ii-subsequence/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/arithmetic-slices-ii-subsequence.md) | 数组、动态规划 | 困难 |
441445
| [0447. 回旋镖的数量](https://leetcode.cn/problems/number-of-boomerangs/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/number-of-boomerangs.md) | 数组、哈希表、数学 | 中等 |
446+
| [0448. 找到所有数组中消失的数字](https://leetcode.cn/problems/find-all-numbers-disappeared-in-an-array/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/find-all-numbers-disappeared-in-an-array.md) | 数组、哈希表 | 简单 |
442447
| [0450. 删除二叉搜索树中的节点](https://leetcode.cn/problems/delete-node-in-a-bst/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/delete-node-in-a-bst.md) | 树、二叉搜索树、二叉树 | 中等 |
443448
| [0451. 根据字符出现频率排序](https://leetcode.cn/problems/sort-characters-by-frequency/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/sort-characters-by-frequency.md) | 哈希表、字符串、桶排序、计数、排序、堆(优先队列) | 中等 |
444449
| [0452. 用最少数量的箭引爆气球](https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/minimum-number-of-arrows-to-burst-balloons.md) | 贪心、数组、排序 | 中等 |
450+
| [0453. 最小操作次数使数组元素相等](https://leetcode.cn/problems/minimum-moves-to-equal-array-elements/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/minimum-moves-to-equal-array-elements.md) | 数组、数学 | 中等 |
445451
| [0454. 四数相加 II](https://leetcode.cn/problems/4sum-ii/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/4sum-ii.md) | 数组、哈希表 | 中等 |
446452
| [0455. 分发饼干](https://leetcode.cn/problems/assign-cookies/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/assign-cookies.md) | 贪心、数组、双指针、排序 | 简单 |
447453
| [0456. 132 模式](https://leetcode.cn/problems/132-pattern/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/132-pattern.md) | 栈、数组、二分查找、有序集合、单调栈 | 中等 |
448454
| [0457. 环形数组是否存在循环](https://leetcode.cn/problems/circular-array-loop/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/circular-array-loop.md) | 数组、哈希表、双指针 | 中等 |
449455
| [0459. 重复的子字符串](https://leetcode.cn/problems/repeated-substring-pattern/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/repeated-substring-pattern.md) | 字符串、字符串匹配 | 简单 |
456+
| [0460. LFU 缓存](https://leetcode.cn/problems/lfu-cache/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/lfu-cache.md) | 设计、哈希表、链表、双向链表 | 困难 |
450457
| [0461. 汉明距离](https://leetcode.cn/problems/hamming-distance/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/hamming-distance.md) | 位运算 | 简单 |
458+
| [0462. 最小操作次数使数组元素相等 II](https://leetcode.cn/problems/minimum-moves-to-equal-array-elements-ii/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/minimum-moves-to-equal-array-elements-ii.md) | 数组、数学、排序 | 中等 |
451459
| [0463. 岛屿的周长](https://leetcode.cn/problems/island-perimeter/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/island-perimeter.md) | 深度优先搜索、广度优先搜索、数组、矩阵 | 简单 |
452460
| [0464. 我能赢吗](https://leetcode.cn/problems/can-i-win/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/can-i-win.md) | 位运算、记忆化搜索、数学、动态规划、状态压缩、博弈 | 中等 |
453461
| [0466. 统计重复个数](https://leetcode.cn/problems/count-the-repetitions/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/count-the-repetitions.md) | 字符串、动态规划 | 困难 |
454462
| [0467. 环绕字符串中唯一的子字符串](https://leetcode.cn/problems/unique-substrings-in-wraparound-string/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/unique-substrings-in-wraparound-string.md) | 字符串、动态规划 | 中等 |
455463
| [0468. 验证IP地址](https://leetcode.cn/problems/validate-ip-address/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/validate-ip-address.md) | 字符串 | 中等 |
464+
| [0470. 用 Rand7() 实现 Rand10()](https://leetcode.cn/problems/implement-rand10-using-rand7/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/implement-rand10-using-rand7.md) | 数学、拒绝采样、概率与统计、随机化 | 中等 |
456465
| [0472. 连接词](https://leetcode.cn/problems/concatenated-words/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/concatenated-words.md) | 深度优先搜索、字典树、数组、字符串、动态规划、排序 | 困难 |
457466
| [0473. 火柴拼正方形](https://leetcode.cn/problems/matchsticks-to-square/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/matchsticks-to-square.md) | 位运算、数组、动态规划、回溯、状态压缩 | 中等 |
458467
| [0474. 一和零](https://leetcode.cn/problems/ones-and-zeroes/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/ones-and-zeroes.md) | 数组、字符串、动态规划 | 中等 |
468+
| [0475. 供暖器](https://leetcode.cn/problems/heaters/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/heaters.md) | 数组、双指针、二分查找、排序 | 中等 |
469+
| [0476. 数字的补数](https://leetcode.cn/problems/number-complement/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/number-complement.md) | 位运算 | 简单 |
470+
| [0478. 在圆内随机生成点](https://leetcode.cn/problems/generate-random-point-in-a-circle/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/generate-random-point-in-a-circle.md) | 几何、数学、拒绝采样、随机化 | 中等 |
471+
| [0479. 最大回文数乘积](https://leetcode.cn/problems/largest-palindrome-product/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/largest-palindrome-product.md) | 数学、枚举 | 困难 |
459472
| [0480. 滑动窗口中位数](https://leetcode.cn/problems/sliding-window-median/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/sliding-window-median.md) | 数组、哈希表、滑动窗口、堆(优先队列) | 困难 |
473+
| [0481. 神奇字符串](https://leetcode.cn/problems/magical-string/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/magical-string.md) | 双指针、字符串 | 中等 |
474+
| [0482. 密钥格式化](https://leetcode.cn/problems/license-key-formatting/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/license-key-formatting.md) | 字符串 | 简单 |
460475
| [0485. 最大连续 1 的个数](https://leetcode.cn/problems/max-consecutive-ones/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/max-consecutive-ones.md) | 数组 | 简单 |
461476
| [0486. 预测赢家](https://leetcode.cn/problems/predict-the-winner/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/predict-the-winner.md) | 递归、数组、数学、动态规划、博弈 | 中等 |
462477
| [0487. 最大连续1的个数 II](https://leetcode.cn/problems/max-consecutive-ones-ii/) | [题解](https://github.com/ITCharge/AlgoNote/tree/main/docs/solutions/0400-0499/max-consecutive-ones-ii.md) | 数组、动态规划、滑动窗口 | 中等 |

docs/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
<img src="https://qcdn.itcharge.cn/images/btn_github_link.svg" width="145" alt="代码仓库"></a>
1515
</div>
1616

17+
如果觉得本项目对你有帮助,欢迎点亮 🌟 Star,支持一下!
18+
1719
## 1. 本书简介
1820

1921
本书不仅仅只是一本算法题解书,更是一本算法与数据结构基础知识的讲解书。
2022

21-
- 超详细的 **「算法与数据结构」** 基础讲解教程,**「LeetCode 800+ 道」** 经典题目详细解析。
23+
- 超详细的 **「算法与数据结构」** 基础讲解教程,**「LeetCode 1000+ 道」** 经典题目详细解析。
2224
- 本项目易于理解,没有大跨度的思维跳跃,项目中使用大量图示、例子来帮助理解。
2325
- 本项目先从基础的数据结构和算法开始讲解,再针对不同分类的数据结构和算法,进行具体题目的讲解分析。让读者可以通过「算法基础理论学习」和「编程实战学习」相结合的方式,彻底的掌握算法知识。
2426
- 本项目从各大知名互联网公司面试算法题中整理汇总了 **「LeetCode 200 道高频面试题」**,帮助面试者更有针对性的准备面试。
@@ -60,7 +62,7 @@
6062

6163
我是一名 iOS / macOS 的开发程序员,研究生毕业于北航软件学院。曾在大学期间学习过算法知识,并参加过 3 年的 ACM 比赛, 但水平有限,未能取得理想成绩。但是这 3 年的 ACM 经历,给我最大的收获是锻炼了自己的逻辑思维和解决实际问题的能力,这种能力为我今后的工作、学习打下了坚实的基础。
6264

63-
我从 2021 年 03 月 30 日开始每日在 LeetCode 刷题,到目前为止日已经刷了 1000+ 道题目,并且完成了 800+ 道题解。努力向着 1000+、1500+、2000+ 道题解前进。
65+
我从 2021 年 03 月 30 日开始每日在 LeetCode 刷题,到目前为止日已经刷了 1800+ 道题目,并且完成了 1000+ 道题解。努力向着 1500+、2000+ 道题解前进。
6466

6567
### 2.2 互助与勘误
6668

docs/others/update_time.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2025-10
22

3+
- 2025-10-27 补充第 400 ~ 499 题的题目解析(增加 15 道题)
34
- 2025-10-24 补充第 400 ~ 499 题的题目解析(增加 12 道题)
45
- 2025-10-23 补全第 300 ~ 399 题的题目解析(增加 20 道题)
56
- 2025-10-22 补充第 300 ~ 399 题的题目解析(增加 13 道题)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# [0442. 数组中重复的数据](https://leetcode.cn/problems/find-all-duplicates-in-an-array/)
2+
3+
- 标签:数组、哈希表
4+
- 难度:中等
5+
6+
## 题目链接
7+
8+
- [0442. 数组中重复的数据 - 力扣](https://leetcode.cn/problems/find-all-duplicates-in-an-array/)
9+
10+
## 题目大意
11+
12+
**描述**
13+
14+
给定一个长度为 $n$ 的整数数组 $nums$,其中 $nums$ 的所有整数都在范围 $[1, n]$ 内,且每个整数出现「最多两次」。
15+
16+
**要求**
17+
18+
请你找出所有出现「两次」的整数,并以数组形式返回。
19+
20+
你必须设计并实现一个时间复杂度为 $O(n)$ 且仅使用常量额外空间(不包括存储输出所需的空间)的算法解决此问题。
21+
22+
**说明**
23+
24+
- $n == nums.length$。
25+
- $1 \le n \le 10^{5}$。
26+
- $1 \le nums[i] \le n$。
27+
- $nums$ 中的每个元素出现「一次」或「两次」。
28+
29+
**示例**
30+
31+
- 示例 1:
32+
33+
```python
34+
输入:nums = [4,3,2,7,8,2,3,1]
35+
输出:[2,3]
36+
```
37+
38+
- 示例 2:
39+
40+
```python
41+
输入:nums = [1,1,2]
42+
输出:[1]
43+
```
44+
45+
## 解题思路
46+
47+
### 思路 1:正负号标记法
48+
49+
由于数组中的元素都在范围 $[1, n]$ 内,且每个整数最多出现两次。可以利用数组中的位置索引本身来表示数字是否存在。
50+
51+
我们可以遍历数组 $nums$,对于每一个元素 $nums[i]$:
52+
- 如果 $nums[abs(nums[i]) - 1] > 0$,说明 $abs(nums[i])$ 第一次出现,将其对应位置的数变为负数作为标记。
53+
- 如果 $nums[abs(nums[i]) - 1] < 0$,说明 $abs(nums[i])$ 已经出现过一次了,此时 $abs(nums[i])$ 就是重复的数字,将其加入到结果数组中。
54+
55+
算法步骤如下:
56+
- 初始化结果数组 $res$。
57+
- 遍历数组 $nums$,对于每个元素 $nums[i]$:
58+
- 计算 $abs(nums[i]) - 1$ 作为索引 $index$。
59+
- 如果 $nums[index] < 0$,说明 $abs(nums[i])$ 是重复数字,将其加入 $res$。
60+
- 否则将 $nums[index]$ 标记为负数,即 $nums[index] = -nums[index]$。
61+
- 遍历结束后,返回结果数组 $res$。
62+
63+
### 思路 1:代码
64+
65+
```python
66+
class Solution:
67+
def findDuplicates(self, nums: List[int]) -> List[int]:
68+
res = []
69+
70+
# 遍历数组,使用正负号标记法
71+
for i in range(len(nums)):
72+
# 计算索引位置
73+
index = abs(nums[i]) - 1
74+
75+
# 如果该位置的数已经是负数,说明已经出现过一次
76+
if nums[index] < 0:
77+
# 将当前元素(取绝对值)加入结果数组
78+
res.append(abs(nums[i]))
79+
else:
80+
# 将该位置的数标记为负数
81+
nums[index] = -nums[index]
82+
83+
return res
84+
```
85+
86+
### 思路 1:复杂度分析
87+
88+
- **时间复杂度**:$O(n)$,其中 $n$ 为数组长度。我们只需要遍历一次数组。
89+
- **空间复杂度**:$O(1)$。除了返回结果数组,只使用了常数额外空间。

0 commit comments

Comments
 (0)