Skip to content

Commit 956c44d

Browse files
Merge branch 'master' into master
2 parents baab804 + c5250fa commit 956c44d

File tree

245 files changed

+2922
-1247
lines changed

Some content is hidden

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

245 files changed

+2922
-1247
lines changed

README.md

Lines changed: 4 additions & 17 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>
@@ -78,18 +78,6 @@
7878
* [Java语言基础课](https://kamacoder.com/course.php?course_id=2)
7979
* [23种设计模式](https://github.com/youngyangyang04/kama-DesignPattern)
8080

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-
9381
* 工具
9482
* [一站式vim配置](https://github.com/youngyangyang04/PowerVim)
9583
* [保姆级Git入门教程,万字详解](https://mp.weixin.qq.com/s/Q_O0ey4C9tryPZaZeJocbA)
@@ -106,7 +94,6 @@
10694
* [关于时间复杂度,你不知道的都在这里!](./problems/前序/关于时间复杂度,你不知道的都在这里!.md)
10795
* [O(n)的算法居然超时了,此时的n究竟是多大?](./problems/前序/On的算法居然超时了,此时的n究竟是多大?.md)
10896
* [通过一道面试题目,讲一讲递归算法的时间复杂度!](./problems/前序/通过一道面试题目,讲一讲递归算法的时间复杂度!.md)
109-
* [本周小结!(算法性能分析系列一)](./problems/周总结/20201210复杂度分析周末总结.md)
11097
* [关于空间复杂度,可能有几个疑问?](./problems/前序/关于空间复杂度,可能有几个疑问?.md)
11198
* [递归算法的时间与空间复杂度分析!](./problems/前序/递归算法的时间与空间复杂度分析.md)
11299
* [刷了这么多题,你了解自己代码的内存消耗么?](./problems/前序/刷了这么多题,你了解自己代码的内存消耗么?.md)
@@ -499,7 +486,7 @@
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

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

-129 KB
Loading

problems/0001.两数之和.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
# 1. 两数之和
@@ -537,8 +537,8 @@ int* twoSum(int* nums, int numsSize, int target, int* returnSize){
537537
return NULL;
538538
}
539539
```
540+
540541
<p align="center">
541542
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
542543
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
543544
</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: 16 additions & 13 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
@@ -111,7 +113,6 @@ class Solution {
111113
for (int i = 0; i <= n; i++) {
112114
fastIndex = fastIndex.next;
113115
}
114-
115116
while (fastIndex != null) {
116117
fastIndex = fastIndex.next;
117118
slowIndex = slowIndex.next;
@@ -193,16 +194,18 @@ func removeNthFromEnd(head *ListNode, n int) *ListNode {
193194
* @param {number} n
194195
* @return {ListNode}
195196
*/
196-
var removeNthFromEnd = function(head, n) {
197-
let ret = new ListNode(0, head),
198-
slow = fast = ret;
199-
while(n--) fast = fast.next;
200-
while (fast.next !== null) {
201-
fast = fast.next;
202-
slow = slow.next
203-
};
204-
slow.next = slow.next.next;
205-
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;
206209
};
207210
```
208211
### 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

problems/0024.两两交换链表中的节点.md

Lines changed: 35 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
# 24. 两两交换链表中的节点
@@ -81,7 +81,7 @@ public:
8181

8282
上面的代码我第一次提交执行用时8ms,打败6.5%的用户,差点吓到我了。
8383

84-
心想应该没有更好的方法了吧,也就$O(n)$的时间复杂度,重复提交几次,这样了:
84+
心想应该没有更好的方法了吧,也就 $O(n)$ 的时间复杂度,重复提交几次,这样了:
8585

8686
![24.两两交换链表中的节点](https://code-thinking.cdn.bcebos.com/pics/24.%E4%B8%A4%E4%B8%A4%E4%BA%A4%E6%8D%A2%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9.png)
8787

@@ -181,6 +181,23 @@ class Solution {
181181
}
182182
```
183183

184+
```java
185+
// 将步骤 2,3 交换顺序,这样不用定义 temp 节点
186+
public ListNode swapPairs(ListNode head) {
187+
ListNode dummy = new ListNode(0, head);
188+
ListNode cur = dummy;
189+
while (cur.next != null && cur.next.next != null) {
190+
ListNode node1 = cur.next;// 第 1 个节点
191+
ListNode node2 = cur.next.next;// 第 2 个节点
192+
cur.next = node2; // 步骤 1
193+
node1.next = node2.next;// 步骤 3
194+
node2.next = node1;// 步骤 2
195+
cur = cur.next.next;
196+
}
197+
return dummy.next;
198+
}
199+
```
200+
184201
### Python:
185202

186203
```python
@@ -285,6 +302,21 @@ var swapPairs = function (head) {
285302
};
286303
```
287304

305+
```javascript
306+
// 递归版本
307+
var swapPairs = function (head) {
308+
if (head == null || head.next == null) {
309+
return head;
310+
}
311+
312+
let after = head.next;
313+
head.next = swapPairs(after.next);
314+
after.next = head;
315+
316+
return after;
317+
};
318+
```
319+
288320
### TypeScript:
289321

290322
```typescript

0 commit comments

Comments
 (0)