Skip to content

Commit 14809cd

Browse files
committed
2 parents 784ed2a + 8aa7159 commit 14809cd

File tree

260 files changed

+8693
-1260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+8693
-1260
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
👉 推荐 [Gitee同步](https://gitee.com/programmercarl/leetcode-master)
44

55
> 1. **介绍** :本项目是一套完整的刷题计划,旨在帮助大家少走弯路,循序渐进学算法,[关注作者](#关于作者)
6-
> 2. **正式出版**[《代码随想录》](https://programmercarl.com/other/publish.html)
7-
> 3. **PDF版本**[「代码随想录」算法精讲 PDF 版本](https://programmercarl.com/other/algo_pdf.html)
6+
> 2. **正式出版**[《代码随想录》](https://programmercarl.com/qita/publish.html)
7+
> 3. **PDF版本**[「代码随想录」算法精讲 PDF 版本](https://programmercarl.com/qita/algo_pdf.html)
88
> 4. **算法公开课**[《代码随想录》算法视频公开课](https://www.bilibili.com/video/BV1fA4y1o715)
99
> 5. **最强八股文**[代码随想录知识星球精华PDF](https://www.programmercarl.com/other/kstar_baguwen.html)
1010
> 6. **刷题顺序** :README已经将刷题顺序排好了,按照顺序一道一道刷就可以。
@@ -14,7 +14,7 @@
1414
1515

1616
<p align="center">
17-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
17+
<a href="https://programmercarl.com/xunlian/xunlianying.html" target="_blank">
1818
<img src="./pics/训练营.png" width="800"/>
1919
</a>
2020
</p>
@@ -74,22 +74,9 @@
7474

7575
* 编程语言
7676
* [C++面试&C++学习指南知识点整理](https://github.com/youngyangyang04/TechCPP)
77-
* [C++语言基础课](https://kamacoder.com/course.php?course_id=1)
78-
* [Java语言基础课](https://kamacoder.com/course.php?course_id=2)
77+
* [编程语言基础课](https://kamacoder.com/courseshop.php)
7978
* [23种设计模式](https://github.com/youngyangyang04/kama-DesignPattern)
8079

81-
* 项目
82-
* [基于跳表的轻量级KV存储引擎](https://github.com/youngyangyang04/Skiplist-CPP)
83-
* [Nosql数据库注入攻击系统](https://github.com/youngyangyang04/NoSQLAttack)
84-
85-
* 编程素养
86-
* [看了这么多代码,谈一谈代码风格!](./problems/前序/代码风格.md)
87-
* [力扣上的代码想在本地编译运行?](./problems/前序/力扣上的代码想在本地编译运行?.md)
88-
* [什么是核心代码模式,什么又是ACM模式?](./problems/前序/什么是核心代码模式,什么又是ACM模式?.md)
89-
* [刷题要不要用库函数](./problems/前序/刷力扣用不用库函数.md)
90-
* [ACM模式如何构造二叉树](./problems/前序/ACM模式如何构建二叉树.md)
91-
* [解密互联网大厂研发流程](./problems/前序/互联网大厂研发流程.md)
92-
9380
* 工具
9481
* [一站式vim配置](https://github.com/youngyangyang04/PowerVim)
9582
* [保姆级Git入门教程,万字详解](https://mp.weixin.qq.com/s/Q_O0ey4C9tryPZaZeJocbA)
@@ -103,13 +90,12 @@
10390
* [BAT级别技术面试流程和注意事项都在这里了](./problems/前序/BAT级别技术面试流程和注意事项都在这里了.md)
10491

10592
* 算法性能分析
106-
* [关于时间复杂度,你不知道的都在这里!](./problems/前序/关于时间复杂度,你不知道的都在这里!.md)
107-
* [O(n)的算法居然超时了,此时的n究竟是多大?](./problems/前序/On的算法居然超时了,此时的n究竟是多大?.md)
108-
* [通过一道面试题目,讲一讲递归算法的时间复杂度!](./problems/前序/通过一道面试题目,讲一讲递归算法的时间复杂度!.md)
109-
* [本周小结!(算法性能分析系列一)](./problems/周总结/20201210复杂度分析周末总结.md)
110-
* [关于空间复杂度,可能有几个疑问?](./problems/前序/关于空间复杂度,可能有几个疑问?.md)
93+
* [关于时间复杂度,你不知道的都在这里!](./problems/前序/时间复杂度.md)
94+
* [O(n)的算法居然超时了,此时的n究竟是多大?](./problems/前序/算法超时.md)
95+
* [通过一道面试题目,讲一讲递归算法的时间复杂度!](./problems/前序/递归算法的时间复杂度.md)
96+
* [关于空间复杂度,可能有几个疑问?](./problems/前序/空间复杂度.md)
11197
* [递归算法的时间与空间复杂度分析!](./problems/前序/递归算法的时间与空间复杂度分析.md)
112-
* [刷了这么多题,你了解自己代码的内存消耗么?](./problems/前序/刷了这么多题,你了解自己代码的内存消耗么?.md)
98+
* [刷了这么多题,你了解自己代码的内存消耗么?](./problems/前序/内存消耗.md)
11399

114100

115101
## 数组
@@ -190,8 +176,9 @@
190176

191177
## 二叉树
192178

179+
193180
题目分类大纲如下:
194-
<img src='https://img-blog.csdnimg.cn/20210219190809451.png' width=600 alt='二叉树大纲'> </img></div>
181+
<img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20240424172231.png' width=600 alt='二叉树大纲'> </img></div>
195182

196183
1. [关于二叉树,你该了解这些!](./problems/二叉树理论基础.md)
197184
2. [二叉树:二叉树的递归遍历](./problems/二叉树的递归遍历.md)
@@ -233,7 +220,7 @@
233220

234221
题目分类大纲如下:
235222

236-
<img src='https://img-blog.csdnimg.cn/20210219192050666.png' width=600 alt='回溯算法大纲'> </img></div>
223+
<img src='https://code-thinking-1253855093.file.myqcloud.com/pics/20240424172311.png' width=600 alt='回溯算法大纲'> </img></div>
237224

238225
1. [关于回溯算法,你该了解这些!](./problems/回溯算法理论基础.md)
239226
2. [回溯算法:77.组合](./problems/0077.组合.md)
@@ -499,32 +486,21 @@
499486

500487
# 贡献者
501488

502-
[点此这里](https://github.com/youngyangyang04/leetcode-master/graphs/contributors)查看LeetCode-Master的所有贡献者。感谢他们补充了LeetCode-Master的其他语言版本,让更多的读者收益于此项目
489+
[点此这里](https://github.com/youngyangyang04/leetcode-master/graphs/contributors)查看LeetCode-Master的所有贡献者。感谢他们补充了LeetCode-Master的其他语言版本,让更多的读者受益于此项目
503490

504491
# Star 趋势
505492

506493
[![Star History Chart](https://api.star-history.com/svg?repos=youngyangyang04/leetcode-master&type=Date)](https://star-history.com/#youngyangyang04/leetcode-master&Date)
507494

508495
# 关于作者
509496

510-
大家好,我是程序员Carl,哈工大师兄,《代码随想录》作者,先后在腾讯和百度从事后端技术研发。对算法和C++后端技术有一定的见解,利用工作之余重新刷leetcode。
497+
大家好,我是程序员Carl,哈工大师兄,《代码随想录》作者,先后在腾讯和百度从事后端技术底层技术研发。
511498

512-
加入「代码随想录」刷题小分队(微信群),可以扫下方二维码,加代码随想录客服微信。
499+
# PDF下载
513500

514-
如果是已工作,备注:姓名-城市-岗位-组队刷题。如果学生,备注:姓名-学校-年级-组队刷题。**备注没有自我介绍不通过哦**
501+
添加如下企业微信,会自动发送给大家PDF版本,顺便可以选择是否加入刷题群。
515502

503+
添加微信记得备注,如果是已工作,备注:姓名-城市-岗位。如果学生,备注:姓名-学校-年级。**备注没有自我介绍不通过哦**
516504

517505
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/第二企业刷题活码.png" data-img="1" width="200" height="200"></img></div>
518506

519-
520-
# 公众号
521-
522-
更多精彩文章持续更新,微信搜索:「代码随想录」第一时间围观,关注后回复:666,可以获得我的所有算法专题原创PDF。
523-
524-
**来看看就知道了,你会发现相见恨晚!**
525-
526-
527-
<a name="公众号"></a>
528-
<div align="center"><img src="https://code-thinking-1253855093.file.myqcloud.com/pics/20211026122841.png" data-img="1" width="650" height="500"></img></div>
529-
530-

pics/网站星球宣传海报.jpg

-129 KB
Loading

problems/0001.两数之和.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88
# 1. 两数之和
@@ -349,6 +349,7 @@ function twoSum(nums: number[], target: number): number[] {
349349
index = helperMap.get(target - nums[i]);
350350
if (index !== undefined) {
351351
resArr = [i, index];
352+
break;
352353
}
353354
helperMap.set(nums[i], i);
354355
}
@@ -537,8 +538,8 @@ int* twoSum(int* nums, int numsSize, int target, int* returnSize){
537538
return NULL;
538539
}
539540
```
541+
540542
<p align="center">
541543
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
542544
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
543545
</a>
544-

problems/0005.最长回文子串.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88

@@ -677,8 +677,8 @@ public class Solution {
677677
}
678678
```
679679

680+
680681
<p align="center">
681682
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
682683
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
683684
</a>
684-

problems/0015.三数之和.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88

9-
> 用哈希表解决了[两数之和](https://programmercarl.com/0001.两数之和.html),那么三数之和呢?
10-
119
# 第15题. 三数之和
1210

1311
[力扣题目链接](https://leetcode.cn/problems/3sum/)
@@ -938,8 +936,8 @@ object Solution {
938936
}
939937
}
940938
```
939+
941940
<p align="center">
942941
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
943942
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
944943
</a>
945-

problems/0017.电话号码的字母组合.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88
# 17.电话号码的字母组合
@@ -260,7 +260,7 @@ class Solution {
260260

261261
}
262262

263-
//每次迭代获取一个字符串,所以会设计大量的字符串拼接,所以这里选择更为高效的 StringBuilder
263+
//每次迭代获取一个字符串,所以会涉及大量的字符串拼接,所以这里选择更为高效的 StringBuilder
264264
StringBuilder temp = new StringBuilder();
265265

266266
//比如digits如果为"23",num 为0,则str表示2对应的 abc
@@ -274,7 +274,7 @@ class Solution {
274274
String str = numString[digits.charAt(num) - '0'];
275275
for (int i = 0; i < str.length(); i++) {
276276
temp.append(str.charAt(i));
277-
//c
277+
//递归,处理下一层
278278
backTracking(digits, numString, num + 1);
279279
//剔除末尾的继续尝试
280280
temp.deleteCharAt(temp.length() - 1);
@@ -765,8 +765,8 @@ public class Solution
765765
}
766766
```
767767

768+
768769
<p align="center">
769770
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
770771
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
771772
</a>
772-

problems/0018.四数之和.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88
> 一样的道理,能解决四数之和
@@ -697,8 +697,8 @@ def four_sum(nums, target)
697697
return result
698698
end
699699
```
700+
700701
<p align="center">
701702
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
702703
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
703704
</a>
704-

problems/0019.删除链表的倒数第N个节点.md

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88

@@ -22,10 +22,12 @@
2222

2323
输入:head = [1,2,3,4,5], n = 2
2424
输出:[1,2,3,5]
25+
2526
示例 2:
2627

2728
输入:head = [1], n = 1
2829
输出:[]
30+
2931
示例 3:
3032

3133
输入:head = [1,2], n = 1
@@ -98,27 +100,32 @@ public:
98100
### Java:
99101
100102
```java
101-
public ListNode removeNthFromEnd(ListNode head, int n){
102-
ListNode dummyNode = new ListNode(0);
103-
dummyNode.next = head;
104-
105-
ListNode fastIndex = dummyNode;
106-
ListNode slowIndex = dummyNode;
107-
108-
// 只要快慢指针相差 n 个结点即可
109-
for (int i = 0; i < n ; i++){
110-
fastIndex = fastIndex.next;
111-
}
103+
class Solution {
104+
public ListNode removeNthFromEnd(ListNode head, int n) {
105+
//新建一个虚拟头节点指向head
106+
ListNode dummyNode = new ListNode(0);
107+
dummyNode.next = head;
108+
//快慢指针指向虚拟头节点
109+
ListNode fastIndex = dummyNode;
110+
ListNode slowIndex = dummyNode;
111+
112+
// 只要快慢指针相差 n 个结点即可
113+
for (int i = 0; i <= n; i++) {
114+
fastIndex = fastIndex.next;
115+
}
116+
while (fastIndex != null) {
117+
fastIndex = fastIndex.next;
118+
slowIndex = slowIndex.next;
119+
}
112120
113-
while (fastIndex != null){
114-
fastIndex = fastIndex.next;
115-
slowIndex = slowIndex.next;
121+
// 此时 slowIndex 的位置就是待删除元素的前一个位置。
122+
// 具体情况可自己画一个链表长度为 3 的图来模拟代码来理解
123+
// 检查 slowIndex.next 是否为 null,以避免空指针异常
124+
if (slowIndex.next != null) {
125+
slowIndex.next = slowIndex.next.next;
126+
}
127+
return dummyNode.next;
116128
}
117-
118-
//此时 slowIndex 的位置就是待删除元素的前一个位置。
119-
//具体情况可自己画一个链表长度为 3 的图来模拟代码来理解
120-
slowIndex.next = slowIndex.next.next;
121-
return dummyNode.next;
122129
}
123130
```
124131

@@ -187,16 +194,18 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode {
187194
* @param {number} n
188195
* @return {ListNode}
189196
*/
190-
var removeNthFromEnd = function(head, n) {
191-
let ret = new ListNode(0, head),
192-
slow = fast = ret;
193-
while(n--) fast = fast.next;
194-
while (fast.next !== null) {
195-
fast = fast.next;
196-
slow = slow.next
197-
};
198-
slow.next = slow.next.next;
199-
return ret.next;
197+
var removeNthFromEnd = function (head, n) {
198+
// 创建哨兵节点,简化解题逻辑
199+
let dummyHead = new ListNode(0, head);
200+
let fast = dummyHead;
201+
let slow = dummyHead;
202+
while (n--) fast = fast.next;
203+
while (fast.next !== null) {
204+
slow = slow.next;
205+
fast = fast.next;
206+
}
207+
slow.next = slow.next.next;
208+
return dummyHead.next;
200209
};
201210
```
202211
### TypeScript:

problems/0020.有效的括号.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<p align="center">
2-
<a href="https://programmercarl.com/other/xunlianying.html" target="_blank">
2+
<a href="https://www.programmercarl.com/xunlian/xunlianying.html" target="_blank">
33
<img src="../pics/训练营.png" width="1000"/>
44
</a>
5-
<p align="center"><strong><a href="https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong></p>
5+
<p align="center"><strong><a href="./qita/join.md">参与本项目</a>,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们受益!</strong></p>
66

77

88

0 commit comments

Comments
 (0)