File tree Expand file tree Collapse file tree 6 files changed +31
-6
lines changed Expand file tree Collapse file tree 6 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,7 @@ object Solution {
417417 }
418418 sum
419419 }
420+ ```
420421
421422
422423C#:
Original file line number Diff line number Diff line change 55<p align =" center " ><strong ><a href =" https://mp.weixin.qq.com/s/tqCxrMEU-ajQumL1i8im9A " >参与本项目</a >,贡献其他语言版本的代码,拥抱开源,让更多学习算法的小伙伴们收益!</strong ></p >
66
77
8- ## 209.长度最小的子数组
8+ # 209.长度最小的子数组
99
1010[ 力扣题目链接] ( https://leetcode-cn.com/problems/minimum-size-subarray-sum/ )
1111
1717输出:2
1818解释:子数组 [ 4,3] 是该条件下的长度最小的子数组。
1919
20+ # 思路
21+
22+ 为了易于大家理解,我特意录制了[ 拿下滑动窗口! | LeetCode 209 长度最小的子数组] ( https://www.bilibili.com/video/BV1tZ4y1q7XE )
2023
2124## 暴力解法
2225
@@ -47,15 +50,29 @@ public:
4750 }
4851};
4952```
50- 时间复杂度:O(n^2)
51- 空间复杂度:O(1)
53+ * 时间复杂度:O(n^2)
54+ * 空间复杂度:O(1)
5255
5356## 滑动窗口
5457
5558接下来就开始介绍数组操作中另一个重要的方法:**滑动窗口**。
5659
5760所谓滑动窗口,**就是不断的调节子序列的起始位置和终止位置,从而得出我们要想的结果**。
5861
62+ 在暴力解法中,是一个for循环滑动窗口的起始位置,一个for循环为滑动窗口的终止位置,用两个for循环 完成了一个不断搜索区间的过程。
63+
64+ 那么滑动窗口如何用一个for循环来完成这个操作呢。
65+
66+ 首先要思考 如果用一个for循环,那么应该表示 滑动窗口的起始位置,还是终止位置。
67+
68+ 如果只用一个for循环来表示 滑动窗口的起始位置,那么如何遍历剩下的终止位置?
69+
70+ 此时难免再次陷入 暴力解法的怪圈。
71+
72+ 所以 只用一个for循环,那么这个循环的索引,一定是表示 滑动窗口的终止位置。
73+
74+ 那么问题来了, 滑动窗口的起始位置如何移动呢?
75+
5976这里还是以题目中的示例来举例,s=7, 数组是 2,3,1,2,4,3,来看一下查找的过程:
6077
6178
@@ -74,7 +91,7 @@ public:
7491
7592窗口的起始位置如何移动:如果当前窗口的值大于s了,窗口就要向前移动了(也就是该缩小了)。
7693
77- 窗口的结束位置如何移动:窗口的结束位置就是遍历数组的指针,窗口的起始位置设置为数组的起始位置就可以了 。
94+ 窗口的结束位置如何移动:窗口的结束位置就是遍历数组的指针,也就是for循环里的索引 。
7895
7996解题的关键在于 窗口的起始位置如何移动,如图所示:
8097
@@ -107,8 +124,8 @@ public:
107124};
108125```
109126
110- 时间复杂度:O(n)
111- 空间复杂度:O(1)
127+ * 时间复杂度:O(n)
128+ * 空间复杂度:O(1)
112129
113130** 一些录友会疑惑为什么时间复杂度是O(n)** 。
114131
Original file line number Diff line number Diff line change @@ -356,6 +356,8 @@ object Solution {
356356 }
357357}
358358
359+ ```
360+
359361
360362C#:
361363``` csharp
Original file line number Diff line number Diff line change @@ -425,6 +425,7 @@ object Solution {
425425 true
426426 }
427427}
428+ ```
428429
429430
430431C#:
Original file line number Diff line number Diff line change @@ -354,6 +354,7 @@ object Solution {
354354 res
355355 }
356356}
357+ ```
357358
358359C#:
359360``` csharp
Original file line number Diff line number Diff line change 11
22# 一台服务器有什么用!
33
4+ * [ 阿里云活动期间服务器购买] ( https://www.aliyun.com/minisite/goods?taskCode=shareNew2205&recordId=3641992&userCode=roof0wob )
5+ * [ 腾讯云活动期间服务器购买] ( https://curl.qcloud.com/EiaMXllu )
6+
47但在组织这场活动的时候,了解到大家都有一个共同的问题: ** 这个服务器究竟有啥用??**
58
69这真是一个好问题,而且我一句两句还说不清楚,所以就专门发文来讲一讲。
You can’t perform that action at this time.
0 commit comments