Skip to content

Commit 77789ff

Browse files
committed
update content
1 parent caf432c commit 77789ff

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ PDF 共两本,一本《labuladong 的算法秘籍》类似教材,帮你系
172172
* [我的刷题心得:算法的本质](https://labuladong.online/algo/fname.html?fname=算法心得)
173173
* [双指针技巧秒杀七道链表题目](https://labuladong.online/algo/fname.html?fname=链表技巧)
174174
* [双指针技巧秒杀七道数组题目](https://labuladong.online/algo/fname.html?fname=双指针技巧)
175+
* [我写了首诗,把滑动窗口算法变成了默写题](https://labuladong.online/algo/fname.html?fname=滑动窗口技巧进阶)
176+
* [我写了首诗,把二分搜索算法变成了默写题](https://labuladong.online/algo/fname.html?fname=二分查找详解)
175177
* [东哥带你刷二叉树(纲领篇)](https://labuladong.online/algo/fname.html?fname=二叉树总结)
176178
* [动态规划解题套路框架](https://labuladong.online/algo/fname.html?fname=动态规划详解进阶)
177179
* [回溯算法解题套路框架](https://labuladong.online/algo/fname.html?fname=回溯算法详解修订版)
178180
* [回溯算法秒杀所有排列/组合/子集问题](https://labuladong.online/algo/fname.html?fname=子集排列组合)
179181
* [球盒模型:回溯算法穷举的两种视角](https://labuladong.online/algo/fname.html?fname=回溯两种视角)
180182
* [BFS 算法解题套路框架](https://labuladong.online/algo/fname.html?fname=BFS框架)
181-
* [我写了首诗,把滑动窗口算法变成了默写题](https://labuladong.online/algo/fname.html?fname=滑动窗口技巧进阶)
182-
* [我写了首诗,把二分搜索算法变成了默写题](https://labuladong.online/algo/fname.html?fname=二分查找详解)
183183
* [算法时空复杂度分析实用指南](https://labuladong.online/algo/fname.html?fname=时间复杂度)
184184

185185

@@ -254,10 +254,10 @@ PDF 共两本,一本《labuladong 的算法秘籍》类似教材,帮你系
254254
* [算法就像搭乐高:带你手撸 LRU 算法](https://labuladong.online/algo/fname.html?fname=LRU算法)
255255
* [算法就像搭乐高:带你手撸 LFU 算法](https://labuladong.online/algo/fname.html?fname=LFU)
256256
* [【强化练习】哈希表更多习题](https://labuladong.online/algo/fname.html?fname=哈希表习题)
257-
* [前缀树算法模板秒杀五道算法题](https://labuladong.online/algo/fname.html?fname=trie)
258-
* [一道求中位数的算法题把我整不会了](https://labuladong.online/algo/fname.html?fname=数据流中位数)
259257
* [二叉堆详解实现优先级队列](https://labuladong.online/algo/fname.html?fname=二叉堆实现)
260258
* [【强化练习】优先级队列经典习题](https://labuladong.online/algo/fname.html?fname=二叉堆习题)
259+
* [一道求中位数的算法题把我整不会了](https://labuladong.online/algo/fname.html?fname=数据流中位数)
260+
* [前缀树算法模板秒杀五道算法题](https://labuladong.online/algo/fname.html?fname=trie)
261261
* [设计朋友圈时间线功能](https://labuladong.online/algo/fname.html?fname=设计Twitter)
262262
* [【强化练习】更多经典设计习题](https://labuladong.online/algo/fname.html?fname=设计习题)
263263

算法思维系列/双指针技巧.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ int removeElement(int[] nums, int val);
214214
<!-- muliti_language -->
215215
```cpp
216216
/* 滑动窗口算法框架 */
217-
void slidingWindow(string s, string t) {
217+
void slidingWindow(string s) {
218218
unordered_map<char, int> window;
219219

220220
int left = 0, right = 0;

算法思维系列/集合划分.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,20 @@ class Solution {
550550

551551

552552

553+
<hr>
554+
<details class="hint-container details">
555+
<summary><strong>引用本文的题目</strong></summary>
556+
557+
<strong>安装 [我的 Chrome 刷题插件](https://labuladong.online/algo/intro/chrome/) 点开下列题目可直接查看解题思路:</strong>
558+
559+
| LeetCode | 力扣 |
560+
| :----: | :----: |
561+
| [473. Matchsticks to Square](https://leetcode.com/problems/matchsticks-to-square/?show=1) | [473. 火柴拼正方形](https://leetcode.cn/problems/matchsticks-to-square/?show=1) |
562+
563+
</details>
564+
<hr>
565+
566+
553567

554568
**_____________**
555569

高频面试系列/判断回文链表.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,42 @@ void traverse(ListNode head) {
133133

134134
<!-- muliti_language -->
135135
```java
136-
// 左侧指针
137-
ListNode left;
136+
class Solution {
137+
// 从左向右移动的指针
138+
ListNode left;
139+
// 从右向左移动的指针
140+
ListNode right;
141+
142+
// 记录链表是否为回文
143+
boolean res = true;
144+
145+
boolean isPalindrome(ListNode head) {
146+
left = head;
147+
traverse(head);
148+
return res;
149+
}
138150

139-
boolean isPalindrome(ListNode head) {
140-
left = head;
141-
return traverse(head);
142-
}
151+
void traverse(ListNode right) {
152+
if (right == null) {
153+
return;
154+
}
143155

144-
boolean traverse(ListNode right) {
145-
if (right == null) return true;
146-
boolean res = traverse(right.next);
147-
// 后序遍历代码
148-
res = res && (right.val == left.val);
149-
left = left.next;
150-
return res;
156+
// 利用递归,走到链表尾部
157+
traverse(right.next);
158+
159+
// 后序遍历位置,此时的 right 指针指向链表右侧尾部
160+
// 所以可以和 left 指针比较,判断是否是回文链表
161+
if (left.val != right.val) {
162+
res = false;
163+
}
164+
left = left.next;
165+
}
151166
}
152167
```
153168

154-
这么做的核心逻辑是什么呢?**实际上就是把链表节点放入一个栈,然后再拿出来,这时候元素顺序就是反的**,只不过我们利用的是递归函数的堆栈而已,如下 GIF 所示
169+
这么做的核心逻辑是什么呢?**实际上就是把链表节点放入一个栈,然后再拿出来,这时候元素顺序就是反的**,只不过我们利用的是递归函数的堆栈而已。如果不好理解,可以看下面这个可视化面板,你可以不断点击 `traverse(right.next);` 这一行代码,就能看出 `left, right` 的移动过程了
155170

156-
![](https://labuladong.online/algo/images/回文链表/1.gif)
171+
<visual slug='is-palindrome' />
157172

158173
当然,无论造一条反转链表还是利用后序遍历,算法的时间和空间复杂度都是 O(N)。下面我们想想,能不能不用额外的空间,解决这个问题呢?
159174

高频面试系列/子集排列组合.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ class Solution {
817817

818818
### 排列(元素无重可复选)
819819

820-
力扣上没有类似的题目,我们不妨先想一下,`nums` 数组中的元素无重复且可复选的情况下,会有哪些排列?
820+
力扣上没有题目直接考察这个场景,我们不妨先想一下,`nums` 数组中的元素无重复且可复选的情况下,会有哪些排列?
821821

822822
比如输入 `nums = [1,2,3]`,那么这种条件下的全排列共有 3^3 = 27 种:
823823

@@ -1027,6 +1027,8 @@ void backtrack(int[] nums) {
10271027
| [368. Largest Divisible Subset](https://leetcode.com/problems/largest-divisible-subset/?show=1) | [368. 最大整除子集](https://leetcode.cn/problems/largest-divisible-subset/?show=1) |
10281028
| [491. Non-decreasing Subsequences](https://leetcode.com/problems/non-decreasing-subsequences/?show=1) | [491. 递增子序列](https://leetcode.cn/problems/non-decreasing-subsequences/?show=1) |
10291029
| [638. Shopping Offers](https://leetcode.com/problems/shopping-offers/?show=1) | [638. 大礼包](https://leetcode.cn/problems/shopping-offers/?show=1) |
1030+
| [967. Numbers With Same Consecutive Differences](https://leetcode.com/problems/numbers-with-same-consecutive-differences/?show=1) | [967. 连续差相同的数字](https://leetcode.cn/problems/numbers-with-same-consecutive-differences/?show=1) |
1031+
| [996. Number of Squareful Arrays](https://leetcode.com/problems/number-of-squareful-arrays/?show=1) | [996. 正方形数组的数目](https://leetcode.cn/problems/number-of-squareful-arrays/?show=1) |
10301032
| - | [剑指 Offer 38. 字符串的排列](https://leetcode.cn/problems/zi-fu-chuan-de-pai-lie-lcof/?show=1) |
10311033
| - | [剑指 Offer II 079. 所有子集](https://leetcode.cn/problems/TVdhkn/?show=1) |
10321034
| - | [剑指 Offer II 080. 含有 k 个元素的组合](https://leetcode.cn/problems/uUsW3B/?show=1) |

0 commit comments

Comments
 (0)